title: Download attachments using Exchange Web Services Java API?
body: <p>I am writing a Java application to download emails using Exchange Web Services. I am using Microsoft's ewsjava API for doing this.</p>
  
  <p>I am able to fetch email headers. But, I am not able to download email attachments using this API. Below is the code snippet.</p>
  
  <pre><code>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 &lt; attachmentsCol.getCount(); i++) {
           FileAttachment attachment = (FileAttachment)attachmentsCol.getPropertyAtIndex(i);
           String name = attachment.getFileName();
           int size = attachment.getContent().length;
        }
     }
  }
  </code></pre>
  
  <p><code>item.getHasAttachments()</code> is returning <code>true</code>, but <code>attachmentsCol.getCount()</code> is <code>0</code>.</p>