Я читаю электронную почту со встроенными/встроенными изображениями, в основном изображение подписи отправителя. Но когда я пытаюсь найти, если email.hasAttachments() возвращает false, но If I Inspect email.getAttachments(); показывает мне встроенные вложения. вот мой код, я делаю что-то неправильно.EWS Java - hasAttachments возвращает false для встроенных вложений/Встроенные вложения
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
}
}
Thanks Glen, Я решил это, добавив дополнительную проверку. if (emailMessage.getHasAttachments() || emailMessage.getAttachments(). GetItems(). Size()> 0) { – Lucky
@ Lucky perfect это сработало для меня тоже! Thanks – Jake
@Jake - рад это слышать. – Lucky