Class Mailer

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

public final class Mailer extends Object

A server's mail support: its transport, its queue and its defaults.

Application code injects a MailSender, which sends through the one its server has. This class is what Mailers.open(Config, DataSource) answers, for code that sets one up by hand -- a command line tool, a check.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Forgets what sent answers.
    void
    Stops sending.
    The transport mails leave through.
    boolean
    Whether the transport could reach its server the last time it tried.
    int
    Mails accepted and neither delivered nor given up on yet.
    void
    send(Mail mail)
    Takes mail for delivery and returns without waiting for it.
    void
    send(Mail... mails)
    Takes several mails; they leave over one connection where the transport has connections.
    void
    sendNow(Mail mail)
    Sends mail on the calling thread and returns when the server has taken it, or throws why it did not.
    The mails sent through the memory: transport, oldest first: what a test asserts on.
    The name of the transport mail leaves through, such as smtp.

    Methods inherited from class Object

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

    • getTransport

      public MailTransport getTransport()
      The transport mails leave through.
    • send

      public void send(Mail mail) throws IOException

      Takes mail for delivery and returns without waiting for it.

      Inside a database transaction the mail is sent only if the transaction commits. A failure to deliver is retried and then recorded, never thrown here; what this throws is a mail that cannot be sent at all -- no sender, a template that does not exist.

      Throws:
      IOException
    • send

      public void send(Mail... mails) throws IOException
      Takes several mails; they leave over one connection where the transport has connections.
      Throws:
      IOException
    • sendNow

      public void sendNow(Mail mail) throws IOException
      Sends mail on the calling thread and returns when the server has taken it, or throws why it did not. No queue, no retry and no regard for a transaction: for a caller that has to know, and has the time to wait.
      Throws:
      IOException
    • sent

      public List<Mail> sent()
      The mails sent through the memory: transport, oldest first: what a test asserts on. Each has its template rendered and its sender filled in. Empty for any other transport.
    • clearSent

      public void clearSent()
      Forgets what sent answers.
    • pending

      public int pending()
      Mails accepted and neither delivered nor given up on yet.
    • isHealthy

      public boolean isHealthy()
      Whether the transport could reach its server the last time it tried.
    • transportName

      public String transportName()
      The name of the transport mail leaves through, such as smtp.
    • close

      public void close()
      Stops sending. Mails that are due are handed over first, for up to five seconds; with a data source the rest are sent by the next start.