Java
Chilkat2 Java
Send Email using smtp-mail.outlook.com with Password Authentication
See more SMTP Examples
Demonstrates how to send an email using smtp-mail.outlook.com using password authentication.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Email;
import com.chilkatsoft.chilkat2.MailMan;
public class ChilkatExample {
public static void main(String[] args) {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
MailMan mailman = new MailMan();
mailman.setSmtpHost("smtp-mail.outlook.com");
mailman.setSmtpPort(587);
mailman.setStartTLS(true);
// Set the SMTP login/password
mailman.setSmtpUsername("OFFICE365_USERNAME");
mailman.setSmtpPassword("OFFICE365_PASSWORD");
// Create a new email object
Email email = new Email();
email.setSubject("This is a test");
email.setBody("This is a test");
email.setFrom("My Name <my_office365_email@outlook.com>");
email.addTo("Chilkat Admin", "admin@chilkatsoft.com");
try {
mailman.sendEmail(email);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println(mailman.getSmtpSessionLog());
try {
mailman.closeSmtpConnection();
} catch (ChilkatException e) {
System.out.println("Connection to SMTP server not closed cleanly.");
}
System.out.println("Email Sent!");
}
}