小编Nar*_*hPS的帖子

使用Exchange Web服务Java API下载附件?

我正在编写一个Java应用程序来使用Exchange Web服务下载电子邮件.我正在使用Microsoft的ewsjava API来执行此操作.

我可以获取电子邮件标题.但是,我无法使用此API下载电子邮件附件.以下是代码段.

FolderId folderId = new FolderId(WellKnownFolderName.Inbox, "mailbox@example.com");
findResults = service.findItems(folderId, view);
for(Item item : findResults.getItems()) {
   if (item.getHasAttachments()) {
      AttachmentCollection attachmentsCol = item.getAttachments();
      System.out.println(attachmentsCol.getCount()); // This is printing zero all the time. My message has one attachment.
      for (int i = 0; i < attachmentsCol.getCount(); i++) {
         FileAttachment attachment = (FileAttachment)attachmentsCol.getPropertyAtIndex(i);
         String name = attachment.getFileName();
         int size = attachment.getContent().length;
      }
   }
}
Run Code Online (Sandbox Code Playgroud)

item.getHasAttachments()是返回true,但是attachmentsCol.getCount()0.

java exchange-server exchangewebservices ewsjavaapi

7
推荐指数
2
解决办法
8883
查看次数