Send Email Message using Exchange Server with WebDav
Contents
[
Hide
]
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:
- Create an instance of the ExchangeClient class.
- Specify server name, username, password, and domain.
- Create an instance of the MailMessage class.
- Specify the from, to, subject and other MailMessage properties.
- Call the ExchangeClient.send() method to send the email.
The sample code below sends email messages using Exchange Server.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |