Class SmtpTransport

java.lang.Object
com.codename1.backend.mail.MailTransport
com.codename1.backend.mail.smtp.SmtpTransport

public final class SmtpTransport extends MailTransport

Sends mail to an SMTP server: a provider's submission endpoint, a relay, or a mail server of one's own.

cn1.mail.url=smtp://apikey:secret@smtp.example.com:587

smtp:// connects in the clear and upgrades with STARTTLS before anything else is said; a server that does not offer it is refused. smtps:// speaks TLS from the first byte, as port 465 does. The defaults are port 587 and 465. A user name and password in the URL are percent-encoded where they contain @, : or /.

Setting Default
cn1.mail.username, cn1.mail.password credentials, when the URL carries none
cn1.mail.smtp.starttls true false sends in the clear to a server with no STARTTLS -- a relay on localhost
cn1.mail.smtp.auth plain, login or xoauth2; unset takes what the server offers. With xoauth2 the password is an OAuth 2 access token
cn1.mail.smtp.helo localhost the name the client gives for itself
cn1.mail.smtp.ca a PEM file of certificates to trust instead of the system's
cn1.mail.timeout.connect 5000 milliseconds a connection may take to open
cn1.mail.timeout.read 60000 milliseconds a reply may take
cn1.mail.pool.max 2 idle connections kept for the next mail
cn1.mail.pool.idle 30000 milliseconds an idle connection is kept

A password is never sent over a connection that is not encrypted, whatever the settings say.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Opens smtp: and smtps: URLs; what the generated wiring registers.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SmtpTransport(String url, Config config)
    A transport for url, with the settings of config, which may be null.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes connections it holds.
    The server's host name.
    What this transport is: smtp, ses, memory, log.
    int
    The server's port.
    boolean
    Whether the transport could reach its server the last time it tried.
    void
    send(String from, String[] recipients, byte[] mime)
    Hands one mail over, returning when the other side has taken it.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SmtpTransport

      public SmtpTransport(String url, Config config) throws IOException
      A transport for url, with the settings of config, which may be null. Nothing connects until the first mail.
      Throws:
      IOException
  • Method Details

    • getName

      public String getName()
      Description copied from class: MailTransport
      What this transport is: smtp, ses, memory, log.
      Specified by:
      getName in class MailTransport
    • getHost

      public String getHost()
      The server's host name.
    • getPort

      public int getPort()
      The server's port.
    • send

      public void send(String from, String[] recipients, byte[] mime) throws IOException
      Description copied from class: MailTransport

      Hands one mail over, returning when the other side has taken it.

      Throws a MailException whose MailException.isPermanent() says whether trying again could help; any other IOException is taken to be a failure of the connection, and is retried.

      • from: the address a bounce goes to, without a display name
      • recipients: the addresses to deliver to, without display names
      • mime: the whole message, CRLF line endings, not dot-stuffed
      Specified by:
      send in class MailTransport
      Throws:
      IOException
    • isHealthy

      public boolean isHealthy()
      Description copied from class: MailTransport
      Whether the transport could reach its server the last time it tried. One that has not tried yet is healthy.
      Overrides:
      isHealthy in class MailTransport
    • close

      public void close()
      Description copied from class: MailTransport
      Closes connections it holds. Never throws.
      Specified by:
      close in class MailTransport