Class MailUtil

  • All Implemented Interfaces:
    Logable, MailUtilInterface
    Direct Known Subclasses:
    ServletMailUtil

    public class MailUtil
    extends Object
    implements MailUtilInterface
    A utility for sending messages via SMTP or SMTPS using Java mail. A MailUtil object contains a complete configuration for sending messages.

    Created by Jeff Gaynor
    on 10/5/11 at 1:18 PM

    • Method Detail

      • sendMessage

        public boolean sendMessage​(String subjectTemplate,
                                   String messageTemplate,
                                   Map replacements,
                                   String newRecipients)
        This allows for sending with a specific subject and message template. This is useful for internally generated messages that may need a lot of customization on the fly. Remember that a template has string delimited with ${KEY} which the replacements map (KEY, VALUE pairs) will render into VALUES.
        Specified by:
        sendMessage in interface MailUtilInterface
        Parameters:
        subjectTemplate -
        messageTemplate -
        replacements -
        Returns:
      • NEWsendMessage

        public boolean NEWsendMessage​(String subjectTemplate,
                                      String messageTemplate,
                                      Map replacements,
                                      String newRecipients)
      • sendMessage

        public boolean sendMessage​(Map replacements)
        This takes a map of replacements for the templates and sends the message.

        This will return a true if the message succeeded and a false otherwise. It will not cause a failure outright, since a failed notification should not bring down your server.

        Specified by:
        sendMessage in interface MailUtilInterface
        Parameters:
        replacements -
        Returns:
      • setMessageTemplate

        public void setMessageTemplate​(String messageTemplate)
      • setSubjectTemplate

        public void setSubjectTemplate​(String subjectTemplate)
      • debug

        public void debug​(String x)
        Description copied from interface: Logable
        Write a debug message to the log.
        Specified by:
        debug in interface Logable
      • setDebugOn

        public void setDebugOn​(boolean debugOn)
        Description copied from interface: Logable
        Enable/disable debugging for this logger
        Specified by:
        setDebugOn in interface Logable
      • isDebugOn

        public boolean isDebugOn()
        Description copied from interface: Logable
        Query if debugging is enabled for this logger.
        Specified by:
        isDebugOn in interface Logable
        Returns:
      • info

        public void info​(String x)
        Description copied from interface: Logable
        Write an informational message to the log
        Specified by:
        info in interface Logable
      • warn

        public void warn​(String x)
        Description copied from interface: Logable
        Write a warning to the log. This indicates a severe, but non-fatal condition exists.
        Specified by:
        warn in interface Logable
      • error

        public void error​(String x)
        Description copied from interface: Logable
        Write an error message to the log. Typically this is invoked as the last command before throwing an exception.
        Specified by:
        error in interface Logable