Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
JWebDAV for Exchange
>
Tutorial
> Download attachments
The following example shows you how to get and download attachments from a message.
import java.io.IOException; import com.independentsoft.webdav.exchange.Attachment; import com.independentsoft.webdav.exchange.WebdavClient; import com.independentsoft.webdav.exchange.WebdavException; public class Example { public static void main(final String[] args) { try { WebdavClient client = new WebdavClient("https://myserver/exchange/emailaddress", "username", "password"); Attachment[] attachments = client.getAttachments("https://myserver/exchange/emailaddress/Inbox/message1.eml"); for (int k = 0; k < attachments.length; k++) { String atachmentUrl = attachments[k].getUrl(); String atachmentFileName = attachments[k].getFileName(); if (atachmentFileName == null) { atachmentFileName = atachmentUrl.substring(atachmentUrl.lastIndexOf("/") + 1); } client.download(atachmentUrl, "c:\\temp\\" + atachmentFileName); } } catch (WebdavException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }