Skip to main content
Version: 8.2405.x.x RR

SMTPClient

The SMTPClient utility implements an SMTP client and can be used to send e-mail messages. It is configured with an optional username and password and a set of properties. The provided username and password will be used if the SMTP Server requires user authentication. The set of properties is used to set up an SMTP session which the SMTPClient holds. The set of properties is expected to contain JavaMail API properties as documented in https://javaee.github.io/javamail/docs/api/overview-summary.html#Properties. In particular, this includes the properties documented in https://javaee.github.io/javamail/docs/api/com/sun/mail/smtp/package-summary.html. If not set explicitly, default values are set for the properties mail.smtp[s].connectiontimeout, mail.smtp[s].timeout and mail.smtp[s].writetimeout.

If used by an AuthState, the SMTPClient can be configured via the properties of the AuthState.

Properties

SMTPS vs SMTP

STPMS is usually mentioned as the TLS secured SMTP protocol. Though SMTPS does not exists as a separate protocol in specifications or in practice.

In Java, the STMPS is nothing more than a shortened form to define SMTP with TLS enabled.

Defining

mail.transport.protocol=smtp
mail.smtp.ssl.enable=true

is the same as

mail.transport.protocol=smtps

This also means, that all properties defined by javadoc in the links above are available for both mail.smtp.* and mail.smtps.*. However, you should make sure to define them consistently. So either use smtps or smtp everywhere, because smtps properties do not fall back to smtp properties!

Example

SMTPClient using SMTP as the transport protocol can be obtained with the following properties:

mail.smtp.host = "mail.yourprovider.ch"
mail.smtp.port = "25"
mail.transport.protocol = "smtp"

SMTPClient using SMTPS as the transport protocol can be obtained with the following properties:

mail.smtps.host = "mail.yourprovider.ch"
mail.smtps.port = "465"
mail.transport.protocol = "smtps"