Send Email Message using Exchange Server with WebDav

You can send email messages using an Exchange Server with the help of the tools in com.aspose.email. The ExchangeClient.send() method accepts a MailMessage instance as a parameter and sends the email. This article explains how to send email messages using an Exchange Client of the API.

Send Email Messages Using Exchange WebDav

To send emails using an Exchange Server:

  1. Create an instance of the ExchangeClient class.
  2. Specify server name, username, password, and domain.
  3. Create an instance of the MailMessage class.
  4. Specify the from, to, subject and other MailMessage properties.
  5. Call the ExchangeClient.send() method to send the email.

The sample code below sends email messages using Exchange Server.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// Create instance of ExchangeClient class by giving credentials
ExchangeClient client = new ExchangeClient("http://MachineName/exchange/username", "username", "password", "domain");
// Create instance of type MailMessage
MailMessage msg = new MailMessage();
msg.setFrom(new MailAddress("sender@domain.com"));
MailAddressCollection collTo = new MailAddressCollection();
collTo.add("recipient@domain.com");
msg.setTo(collTo);
msg.setSubject("Sending message from exchange server");
msg.setHtmlBody("<h3>sending message from exchange server</h3>");
// Send the message
client.send(msg);