Send Email via Exchange Web Service in Java
A progressive solution to implement email sending capability into Java projects.
Download Free TrialHow to Send a Message via EWS using the Java API
The following code sample will guide you through the process of message sending using the Java library, making it easier than ever to integrate email functionality into your applications. In a few lines of code, you will establish a connection to the EWS server, create a new message and send it being sure of its delivery or you will get a clear error handling support if any.
import com.aspose.email.*;
// Create instance of IEWSClient class by giving credentials
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "username", "password", "domain");
// Create instance of type MailMessage
MailMessage msg = new MailMessage();
msg.setFrom(MailAddress.to_MailAddress("sender@domain.com"));
msg.setTo(MailAddressCollection.to_MailAddressCollection("recipient@ domain.com "));
msg.setSubject("Sending message from exchange server");
msg.setHtmlBody("<h3>sending message from exchange server</h3>");
try {
// Send the message
client.send(msg);
System.out.println("Email sent successfully.");
} catch (Exception e) {
e.printStackTrace();
}
Utility Features
Apart from the reliability and simplicity of its use, the library provides you with the following capabilities in the work with the EWS Client:
Reading mailbox files and filtering.
Managing conversation and calendar items.
Working with contacts, distribution lists, tasks, appointments etc.
Support for TLS and AutodiscoverService.
Getting messages from a shared mailbox and more.
About the Java API in Short
In this article we’ve introduced Aspose.Email for Java, a trusted companion for making email communication effortless and efficient. From sending and receiving emails to advanced email processing and automation, these capabilities make it a versatile and comprehensive library. Don’t miss the opportunity to streamline your email-related processes and elevate your Java applications.