0
我有一些問題,在使用EWS的Java API 1.3快照得到一些附件,我想附件在我的電子郵件,在這裏我的代碼:EWS的Java API獲取附件
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());
}
我的問題是可以得到另一有沒有附件,總是跳過帶有附件的電子郵件電子郵件的例子是這樣的, 在我的收件箱我從這個郵件列表
- :[email protected](有附件)
- 從:[email protected](no att achment)
- 來自:[email protected](有附件)
- 來自:[email protected](不帶附件)
當我跑我的代碼,它總能得到一個沒有電子郵件附件,這樣的:
- 從:[email protected](無附着)
- 從:[email protected](無附着)
並跳過有附件的其他電子郵件,我不知道如何發生這種情況。有人能幫助我嗎?
您正在使用哪個java api?鏈接? – Mahesha999 2015-02-12 08:47:57
我使用EWS的Java API 1.3快照, 我從Maven倉庫在這裏下載和我的pom.xml com.microsoft.office EWS-Java的API 系統 1.3快照 –
2015-02-13 09:17:50
看起來是正確的,可能會捕獲SOAP包與TraceListener將有所幫助。這裏有一些鏈接:[1](https://msdn.microsoft.com/en-us/library/office/dd633676(v = exchg.80).aspx),[2](https://msdn.microsoft .com/en-us/library/office/dd633655(v = exchg.80).aspx),[3](https://msdn.microsoft.com/en-us/library/office/dn495632(v = exchg) .150).aspx)另外我會建議你在[exchange development forum](https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=exchangesvrdevelopment)上發佈這個問題以獲得精確響應。當我面對類似奇怪的事情時,這幫助了我。 – Mahesha999 2015-02-13 10:14:02