Class Mailers

java.lang.Object
com.codename1.backend.mail.Mailers

public final class Mailers extends Object

Opens the Mailer a configuration names, and finds the one of the calling thread's server.

Setting Default
cn1.mail.url memory: smtp://host:587, smtps://host:465, ses://region, log:, memory:
cn1.mail.from the sender of a mail that names none: Shop <no-reply@example.com>
cn1.mail.domain the sender's the domain a Message-ID is made in
cn1.mail.username, cn1.mail.password credentials, when the URL carries none
cn1.mail.retry.max-attempts 6 attempts before a mail is given up on
cn1.mail.retry.backoff 30000 milliseconds before the second attempt
cn1.mail.retry.multiplier 4 what each later wait is multiplied by
cn1.mail.retry.max-backoff 3600000 the longest wait
cn1.mail.outbox.sweep 10000 milliseconds between looks for mails a stopped server left

Each transport documents its own settings. Without cn1.mail.url, Spring Boot's spring.mail.host selects SMTP, with spring.mail.port, spring.mail.username and spring.mail.password.

A transport is compiled into an application only when its configuration names it: the build registers that one transport's factory with register(String, Mailers.TransportFactory), so SMTP adds nothing to an application that sends through an API, and neither adds anything to one that sends no mail.

  • Method Details

    • register

      public static void register(String scheme, Mailers.TransportFactory factory)
      Makes scheme (smtp, ses) open through factory. Called by the generated wiring, never by application code.
    • bindDataSource

      public static void bindDataSource(DataSource dataSource) throws IOException
      Gives the calling thread's server's mail support its data source, where the outbox is kept. Called by the generated wiring before any bean can send.
      Throws:
      IOException
    • current

      public static Mailer current() throws IOException
      The mail support of the calling thread's server: opened from its configuration the first time it is asked for, closed when the server stops.
      Throws:
      IOException
    • isConfigured

      public static boolean isConfigured(Config config) throws IOException
      Whether config names a transport that sends.
      Throws:
      IOException
    • url

      public static String url(Config config) throws IOException
      The URL config names, or null when it names none.
      Throws:
      IOException
    • open

      public static Mailer open(Config config, DataSource dataSource) throws IOException

      Opens the mail support config names; the caller closes it.

      • dataSource: the server's, or null; where the outbox is kept
      Throws:
      IOException