java - EWS Java - hasAttachments 对于内联/嵌入式附件返回 false

标签 java exchangewebservices email-attachments ewsjavaapi

我正在阅读带有内联/嵌入图像的电子邮件,主要是发件人签名图像。 但是当我尝试查找 email.hasAttachments() 是否返回 false 时,但如果我检查 email.getAttachments(); 它会显示内联附件。这是我的代码,我做错了什么吗?

try {
        Item itm = Item.bind(service, itemId, new PropertySet(
                BasePropertySet.FirstClassProperties,
                ItemSchema.Attachments,ItemSchema.HasAttachments,
                ItemSchema.extendedProperties));

        emailMessage = EmailMessage.bind(service, itm.getId(),
                new PropertySet(BasePropertySet.FirstClassProperties,
                        EmailMessageSchema.Attachments, EmailMessageSchema.HasAttachments));

        log.info(From: " + emailMessage.getFrom());
        log.info(Subject: " + emailMessage.getSubject());
        log.info(Received: " + emailMessage.getDateTimeReceived());

        //get email attachments.
        attachments = getEmailAttachments(emailMessage, properties);
    }

    //getEmailAttachments() method.
    try {
        //check if the email has attachments.

        if (emailMessage.getHasAttachments()) { //returns false here
            //get all the attachments
            AttachmentCollection attachmentsCol = emailMessage.getAttachments();// will return the attachments
            log.info("File Count: " +attachmentsCol.getCount());
            //loop over the attachments
            for (int i = 0; i < attachmentsCol.getCount(); i++) {
                Attachment attchment = attachmentsCol.getPropertyAtIndex(i);

                if (attchment.getIsInline()) {
                    log.info("There is an inline attachment.");
                }
                //FileAttachment - Represents a file that is attached to an email item
                if (attchment instanceof FileAttachment) {
                    //my code here
                } else if (attchment instanceof ItemAttachment) { //ItemAttachment - Represents an Exchange item that is attached to another Exchange item.
                    //my code here
                }
            }

最佳答案

HasAttachments 是一个计算属性,其值基于其他 props。 Outlook 可以设置的一个影响此问题的属性是 SmartNoAttach 属性(您可以在 Mapi 编辑器中查看此属性的值),该属性可以有效地隐藏 Outlook 中的回形针,其中邮件具有签名等内联附件(并且没有真正的附件)。但它也会影响EWS中的该属性值。

关于java - EWS Java - hasAttachments 对于内联/嵌入式附件返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39601947/

相关文章:

c# - 在 MSAL 中获取 EWS 的委托(delegate)权限,无需 PublicClientApplicationBuilder 和 AcquireTokenInteractive

objective-c - 使用 Microsoft Exchange Services 2007 的 Cocoa Mac 应用程序

Java EWS API 按日期搜索邮件

java - 过滤图像的最快性能

java - 超过锁定等待超时;尝试使用 JDBC 重新启动事务

java - 我的程序在 while 循环之后不会执行任何内容

c# - 如何在 C# 中使用 MimeKit 发送电子邮件

java - 插入USB热点后简单的Java程序慢100倍

javascript - 如何使用客户端 gmail API 发送电子邮件,其中包含 html 内容和图像作为附件

Android:接收电子邮件附件的 Intent