2014
01.28

This note explains how to send an e-mail message using JavaMail, including using an SSL connection or the STARTTLS built-in security.

This note applies to:

  • Java version 1.7
  • JavaMail version 1.4.1

If using Maven, the JavaMail artifact can be obtained using the following dependency:

Often, a properties file is loaded to configure the SMTP transport layer. This allows a user to configure outgoing mail server without having to change the code. Here is a code excerpt to obtain a session and

Plain Text

For plain text access to the SMTP service, the following properties can be used:

STARTTLS

For sending a message using the STARTTLS built-in security, the following properties should be used:

SSL

For sending a message using SMTP over SSL, the following properties should be used:

Debugging

There is a property which sets the “debug” mode for JavaMail. It can be set with the following properties:

1 comment so far

Add Your Comment
  1. This was especially helpful given the default would be to use TLS (which is a problem if the system is not configured with the certificates). The Plain Text reference was exactly what we needed.