Class MailService


  • public class MailService
    extends Object
    This class, working in a singleton mode, is a utility for sending mail messages.
    Author:
    pvandermaesen
    • Method Detail

      • getInstance

        public static MailService getInstance​(MailConfig mailConfig)
        This method is kept to be able to use this class outside a Servlet context
        Parameters:
        mailConfig - config for mailing.
        Returns:
        the MailingManager singleton
      • getMailSession

        public static final javax.mail.Session getMailSession​(MailConfig mailConfig)
                                                       throws javax.mail.MessagingException
        Throws:
        javax.mail.MessagingException
      • getMailTransport

        public static final javax.mail.Transport getMailTransport​(MailConfig mailConfig)
                                                           throws javax.mail.MessagingException
        Throws:
        javax.mail.MessagingException
      • sendMail

        public String sendMail​(EMail email)
                        throws javax.mail.MessagingException
        Throws:
        javax.mail.MessagingException
      • sendMailAsyncron

        public void sendMailAsyncron​(EMail email)
      • sendMailAsyncron

        public void sendMailAsyncron​(javax.mail.Transport transport,
                                     EMail email)
      • sendMail

        public String sendMail​(javax.mail.Transport transport,
                               EMail email)
                        throws javax.mail.MessagingException
        Throws:
        javax.mail.MessagingException
      • sendMail

        public String sendMail​(javax.mail.Transport transport,
                               javax.mail.internet.InternetAddress sender,
                               javax.mail.internet.InternetAddress recipient,
                               List<javax.mail.internet.InternetAddress> ccRecipients,
                               List<javax.mail.internet.InternetAddress> bccRecipients,
                               String subject,
                               String content,
                               boolean isHTML,
                               String unsubribeLink,
                               DKIMBean dkinBean)
                        throws javax.mail.MessagingException
        Send one mail to one recipient and multiple BCC recipients (in one mail).
        Parameters:
        transport - transport connection, if null transport is create inside the method
        sender - the "From" field
        recipient - the "To" field
        bccRecipients - the "Bcc" field with multiple addresses.
        subject - the Subject of the message
        content - the Content of the message
        isHTML - flag indicating wether the Content is html (true) or text (false)
        Throws:
        javax.mail.MessagingException - Forwarded exception from javax.mail
        IllegalArgumentException - if no recipient provided or no sender
      • sendMail

        public void sendMail​(javax.mail.Transport transport,
                             javax.mail.internet.InternetAddress sender,
                             javax.mail.internet.InternetAddress recipient,
                             javax.mail.internet.InternetAddress ccRecipient,
                             javax.mail.internet.InternetAddress bccRecipient,
                             String subject,
                             String content,
                             boolean isHTML)
                      throws javax.mail.MessagingException
        Throws:
        javax.mail.MessagingException
      • sendMail

        public void sendMail​(javax.mail.Transport transport,
                             javax.mail.internet.InternetAddress sender,
                             javax.mail.internet.InternetAddress recipient,
                             javax.mail.internet.InternetAddress ccRecipient,
                             javax.mail.internet.InternetAddress bccRecipient,
                             String subject,
                             String content,
                             String contentTxt,
                             boolean isHTML,
                             DKIMBean dkimBean)
                      throws javax.mail.MessagingException
        Throws:
        javax.mail.MessagingException
      • getMailConfig

        public MailConfig getMailConfig()
      • sendMail

        public void sendMail​(javax.mail.Transport transport,
                             javax.mail.internet.InternetAddress sender,
                             javax.mail.internet.InternetAddress recipient,
                             String subject,
                             String content,
                             boolean isHTML,
                             String unsubribeLink)
                      throws javax.mail.MessagingException
        Send one mail to one recipient.
        Parameters:
        transport - transport connection, if null transport is create inside the method
        sender - the "From" field
        recipient - the "To" field
        subject - the Subject of the message
        content - the Content of the message
        isHTML - flag indicating wether the Content is html (true) or text (false)
        Throws:
        javax.mail.MessagingException - Forwarded exception from javax.mail
        IllegalArgumentException - if no recipient provided or no sender
      • sendMail

        public String sendMail​(javax.mail.Transport transport,
                               javax.mail.internet.InternetAddress sender,
                               javax.mail.internet.InternetAddress recipient,
                               String subject,
                               String content,
                               boolean isHTML,
                               String unsubribeLink,
                               DKIMBean dkinBean,
                               String mailId)
                        throws javax.mail.MessagingException
        Throws:
        javax.mail.MessagingException
      • sendMail

        public void sendMail​(javax.mail.internet.InternetAddress sender,
                             javax.mail.internet.InternetAddress recipient,
                             String subject,
                             String content,
                             boolean isHTML)
                      throws javax.mail.MessagingException
        Throws:
        javax.mail.MessagingException
      • sendMail

        public void sendMail​(javax.mail.internet.InternetAddress sender,
                             javax.mail.internet.InternetAddress recipient,
                             String subject,
                             String content,
                             boolean isHTML,
                             DKIMBean dkim)
                      throws javax.mail.MessagingException
        Throws:
        javax.mail.MessagingException
      • sendMail

        public void sendMail​(GlobalContext globalContext,
                             javax.mail.internet.InternetAddress sender,
                             javax.mail.internet.InternetAddress recipient,
                             String subject,
                             String content,
                             boolean isHTML)
                      throws javax.mail.MessagingException
        Throws:
        javax.mail.MessagingException
      • resetInstance

        public static void resetInstance()
      • messageToText

        public static String messageToText​(javax.mail.internet.MimeMultipart part)
                                    throws IOException,
                                           javax.mail.MessagingException
        Throws:
        IOException
        javax.mail.MessagingException
      • messageToDKIMBody

        public static String messageToDKIMBody​(javax.mail.internet.MimeMultipart msg,
                                               OutputStream out)
                                        throws IOException,
                                               javax.mail.MessagingException
        Throws:
        IOException
        javax.mail.MessagingException
      • _messageToDKIMBody

        public static String _messageToDKIMBody​(javax.mail.internet.MimeMultipart part)
                                         throws IOException,
                                                javax.mail.MessagingException
        Throws:
        IOException
        javax.mail.MessagingException
      • getDefaultSenderEmail

        public static String getDefaultSenderEmail​(ContentContext ctx,
                                                   String email)
        get the default mail sender.
        Parameters:
        ctx -
        email -
        Returns:
        if email is a email return it
      • getDefaultReceiverEmail

        public static String getDefaultReceiverEmail​(ContentContext ctx,
                                                     String email)
        get the default mail receiver.
        Parameters:
        ctx -
        email -
        Returns:
        if email is a email return it