Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
JWebDAV for Exchange
>
Tutorial
> Send message with embedded image
The following example shows you how to send HTML message with embedded image in the message body.
import java.io.IOException; import com.independentsoft.webdav.exchange.Mailbox; import com.independentsoft.webdav.exchange.Message; import com.independentsoft.webdav.exchange.MultiStatus; import com.independentsoft.webdav.exchange.Property; 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"); Mailbox myMailbox = client.getMailbox("https://myserver/exchange/emailaddress"); Message message1 = new Message(); message1.setSubject("Embedded image test"); message1.setHtmlBody("This is the message body. Below is an embedded image.
"); message1.setTo("username@mydomain.com"); message1.addAttachment("c:\\temp\\image001.gif"); MultiStatus multiStatus = client.createItem(message1); String messageUrl = multiStatus.getResponses()[0].getHRef(); Property property1 = new Property("x3712001f", "http://schemas.microsoft.com/mapi/proptag/", "image001.gif"); Property property2 = new Property("x370e001f", "http://schemas.microsoft.com/mapi/proptag/", "image/gif"); client.setProperty(messageUrl + "/image001.gif", property1); client.setProperty(messageUrl + "/image001.gif", property2); //Send message client.move(messageUrl, myMailbox.getMailSubmission()); } catch (WebdavException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }