EWS Java - hasAttachments为内联/嵌入式附件返回false

时间:2016-09-20 19:04:05

标签: 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
                }
            }

1 个答案:

答案 0 :(得分:2)

HasAttachments是一个计算属性,其值基于其他道具。 Outlook可以设置的一个影响这一属性的属性是SmartNoAttach属性(您可以在Mapi编辑器中查看此prop的值),该属性有效地隐藏了Outlook中的Paperclip,其中消息具有内联附件,如签名(并且没有真正的附件)。但它也会影响EWS中的这个属性值。