我正在阅读带有内联/嵌入图像的电子邮件,主要是发件人签名图像。 但是当我尝试查找 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/