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

标签 java exchange-server exchangewebservices ewsjavaapi

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

我能够获取电子邮件 header 。但是,我无法使用此 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;
      }
   }
}

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

最佳答案

您需要先加载属性 Attachments,然后才能在您的代码中使用它们。您为传递给 FindItems 方法的 ItemView 对象设置它。

或者您可以先找到项目,然后调用 service.LoadPropertiesForItems 并传递 findIesults 和添加了 EmailMessageSchema.Attachments 的 PropertySet 对象

关于java - 使用 Exchange Web 服务 Java API 下载附件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6585994/

相关文章:

Java迭代器从有序集合的特定元素开始

java - 使用ScalaTest测试包含@Autowired和私有(private)字段的java

.net - 将 .Net 服务与 Microsoft Exchange 集成

exchangewebservices - 如何使用托管 API 取消订阅 EWS 推送通知

asp.net - AD用户认证

java - 如何反混淆jar文件

java - Hibernate - 自动或手动 ID - 在集群环境中

html - 什么是 ocsi 属性?

c# - EWS 找不到自动发现服务

ios - NSURLSession 多个并发请求被 Exchange 服务器拒绝