Class MailSender

  • public class MailSender
    extends java.lang.Object
    The mail sender can send emails directly or queued, with a reply callback. It must be configured in either the Designer or the Server.

    All mails that are queued are stored in a mail queue folder. This means that if you stop the e.g. server and restart it, no mail will be unsent. The worst that might happen is that a mail is sent twice (but this is a very thin chance to happen).

    Christopher Mindus
    • Constructor Detail

      • MailSender

        public MailSender​(MailProps pc,
                          java.util.concurrent.ExecutorService executorService,
        Creates a new instance of the mail sender with the specified settings. Any previous mail sender with remaining messages to send will still do its work.
        pc - The mail property container.
        executorService - Executor service for mail sending, null when not queueing mails, just for test sending.
        mailQueueDirectory - Mail queue directory. If it doesn't exist, it is created.
        Throws: - If the mail queue directory does not exist.
        NoSuchProviderException - If the "smtp" or "smtps" providers do not exist!
        AddressException - If the default sender failed to parse.
    • Method Detail

      • getInstance

        public static MailSender getInstance()
        Gets the default instance of the mail sender.
        The default instance, null if none is configured.
      • getInstance

        public static MailSender getInstance​(java.lang.String name)
        Gets the default instance of the mail sender.
        name - The name of the mail sender, null for default.
        The default instance, null if none is configured.
      • getInstances

        public static MailSender[] getInstances()
        Returns all configured mail senders.
        The array may be empty if no mail senders are configured.
      • stopAll

        public static int stopAll​(long timeout)
                           throws java.lang.InterruptedException
        Requests to stop all mail senders.
        timeout - Timeout in milliseconds to wait.
        Number of mails left to send (in all mail queues), zero means none.
        java.lang.InterruptedException - If the wait is interrupted.
      • getDescription

        public java.lang.String getDescription()
        Gets the description of this mail sender.
        A description string, or null if none is defined.
      • getDefaultSender

        public InternetAddress getDefaultSender()
        The default 'Sender' for mails.
        The default 'Sender' for mails, null for none.
      • getDefaultReplyTo

        public InternetAddress getDefaultReplyTo()
        The default 'Reply To' for mails.
        The default 'Reply To' for mails, null for none.
      • getDefaultCCs

        public InternetAddress[] getDefaultCCs()
        The default CC's for mails.
        The default CC's for mails, null for none.
      • getDefaultBCCs

        public InternetAddress[] getDefaultBCCs()
        The default BCC's for mails.
        The default BCC's for mails, null for none.
      • isDisposed

        public boolean isDisposed()
        Checks if the mail sender is disposed of.
        true if disposed of, false otherwise.
      • getQueuedMailCount

        public int getQueuedMailCount()
        Returns how mail mails are currently queued for sending.
        The number of queued mails.
      • dispose

        public void dispose()
        Disposes of the current mail sender and leaves unsent mail queued.
      • deleteMailDirectory

        public void deleteMailDirectory()
        Deletes all unsent mails and the mail folder. This call should be made in preference once the mail sender has been disposed of.
        Throws: - If the mail folder failed to be deleted.