Class Mailer


  • public class Mailer
    extends Object
    Facade for sending emails with the JavaMail API.
    • Field Detail

      • logger

        private static final org.slf4j.Logger logger
        The Constant logger.
      • from

        private String from
        The from.
      • smtp

        private String smtp
        The smtp.
      • defaultTo

        private String defaultTo
        The default to.
      • subjectPrefix

        private String subjectPrefix
        The subject prefix.
    • Constructor Detail

      • Mailer

        public Mailer()
        Instantiates a new mailer.
      • Mailer

        public Mailer​(String from)
        Instantiates a new mailer.
        Parameters:
        from - the from
      • Mailer

        public Mailer​(String from,
                      String smtp)
        Instantiates a new mailer.
        Parameters:
        from - the from
        smtp - the smtp
    • Method Detail

      • getFrom

        public String getFrom()
        Gets the from.
        Returns:
        the from
      • getSmtp

        public String getSmtp()
        Gets the smtp.
        Returns:
        the smtp
      • setFrom

        public void setFrom​(String from)
        Sets the from.
        Parameters:
        from - the new from
      • setSmtp

        public void setSmtp​(String smtp)
        Sets the smtp.
        Parameters:
        smtp - the new smtp
      • getDefaultTo

        public String getDefaultTo()
        Gets the default to.
        Returns:
        the default to
      • setDefaultTo

        @Value("${psiprobe.tools.mail.to}")
        public void setDefaultTo​(String defaultTo)
        Sets the default to.
        Parameters:
        defaultTo - the new default to
      • getSubjectPrefix

        public String getSubjectPrefix()
        Gets the subject prefix.
        Returns:
        the subject prefix
      • setSubjectPrefix

        @Value("${psiprobe.tools.mail.subjectPrefix}")
        public void setSubjectPrefix​(String subjectPrefix)
        Sets the subject prefix.
        Parameters:
        subjectPrefix - the new subject prefix
      • send

        public void send​(MailMessage mailMessage)
                  throws javax.mail.MessagingException
        Send.
        Parameters:
        mailMessage - the mail message
        Throws:
        javax.mail.MessagingException - the messaging exception
      • createMimeMessage

        private javax.mail.internet.MimeMessage createMimeMessage​(javax.mail.Session session,
                                                                  MailMessage mailMessage)
                                                           throws javax.mail.MessagingException
        Creates the mime message.
        Parameters:
        session - the session
        mailMessage - the mail message
        Returns:
        the mime message
        Throws:
        javax.mail.MessagingException - the messaging exception
      • createAddresses

        private static javax.mail.internet.InternetAddress[] createAddresses​(String[] addresses)
                                                                      throws javax.mail.internet.AddressException
        Creates the addresses.
        Parameters:
        addresses - the addresses
        Returns:
        the Internet address[]
        Throws:
        javax.mail.internet.AddressException - the address exception
      • createAttachmentPart

        private static javax.mail.internet.MimeBodyPart createAttachmentPart​(DataSource attachment)
                                                                      throws javax.mail.MessagingException
        Creates the attachment part.
        Parameters:
        attachment - the attachment
        Returns:
        the mime body part
        Throws:
        javax.mail.MessagingException - the messaging exception
      • createMessageBodyPart

        private static javax.mail.internet.MimeBodyPart createMessageBodyPart​(String body,
                                                                              boolean html)
                                                                       throws javax.mail.MessagingException
        Creates the message body part.
        Parameters:
        body - the body
        html - the html
        Returns:
        the mime body part
        Throws:
        javax.mail.MessagingException - the messaging exception