I have some issue in getting some attachment using ews java API 1.3 SNAPSHOT, i want to get Attachment in my email, here my code :
try {
ExchangeService service;
service.setUrl(new URI("https://" + myserver + "/ews/Exchange.asmx"));
ExchangeCredentials credentials = new WebCredentials(username, password);
service.setCredentials(credentials);
ItemView view = new ItemView(Integer.MAX_VALUE);
view.getOrderBy().add(ItemSchema.DateTimeReceived, SortDirection.Ascending);
Folder folder = Folder.bind(service, WellKnownFolderName.Inbox);
FindItemsResults<Item> results = service.findItems(folder.getId(),view);
service.loadPropertiesForItems(results, new PropertySet(BasePropertySet.FirstClassProperties, EmailMessageSchema.Attachments));
for (Item item : results) {
Item itm = Item.bind(service, item.getId(), new PropertySet(BasePropertySet.FirstClassProperties, EmailMessageSchema.Attachments));
EmailMessage emailMessage = EmailMessage.bind(service, itm.getId(), new PropertySet(BasePropertySet.FirstClassProperties, EmailMessageSchema.Attachments));
if (emailMessage.getHasAttachments()) {
for (Attachment attachment : emailMessage.getAttachments()) {
String FileExtension = getFileExtension(attachment.getName());
File TempFile = File.createTempFile(attachment.getName(), FileExtension);
attachment.load(TempFile.getAbsolutePath());
}
}
}
} catch (Exception e) {
logger.error("Error ", e.getMessage());
}
My issue is it can get another email that has no attachment and always skip email that has an attachment, the example is like this, In my inbox i have this email list
- from: a@gmail.com (has attachment)
- from: b@mycompany.com (no attachment)
- from: c@hiscompany.com (has attachment)
- from: d@mycompany.com (no attachment)
And when i run my code, it always get email that has no attachment, like this:
- from: b@mycompany.com (no attachment)
- from: d@mycompany.com (no attachment)
and skip the other email that has attachment, i have no idea how can this happen. Can someone help me please?