Class MailBuilder


  • public final class MailBuilder
    extends Object
    The MailBuilder defines fluent API to build MimeMessage and if required can send the built message directly.
    • Constructor Detail

      • MailBuilder

        public MailBuilder​(javax.mail.Session session)
    • Method Detail

      • attach

        public MailBuilder attach​(String name,
                                  String link,
                                  String cid)
        Attach a file referenced by the given link.

        If you want to reference the attachment as inline image, provide content id wrapped by angle brackets and refer the image with content id without angle brackets. For example:

         builder.html("<img src='cid:logo.png'>").attach("logo.png", "/path/to/logo.png", "<logo.png>").send();
         
        Parameters:
        name - attachment file name
        link - attachment file link (url or file path)
        cid - content id
        Returns:
        this
      • inline

        public MailBuilder inline​(String name,
                                  String link)
        Attach a file as inline content.
        Parameters:
        name - attachment file name
        link - attachment file link (url or file path)
        Returns:
        this
      • build

        public javax.mail.internet.MimeMessage build()
                                              throws javax.mail.MessagingException,
                                                     IOException
        Build a new MimeMessage instance from the provided details.
        Returns:
        an instance of MimeMessage
        Throws:
        IOException - generally thrown by DataHandler
        javax.mail.MessagingException - for failure
      • build

        public javax.mail.internet.MimeMessage build​(String messageId)
                                              throws javax.mail.MessagingException,
                                                     IOException
        Build a new MimeMessage instance from the provided details.
        Parameters:
        messageId - custom "Message-ID" to use, null to use auto-generated
        Returns:
        an instance of MimeMessage
        Throws:
        IOException - generally thrown by DataHandler
        javax.mail.MessagingException - for failure
      • send

        public javax.mail.internet.MimeMessage send​(Date date)
                                             throws javax.mail.MessagingException,
                                                    IOException
        Send the message with given send date.
        Parameters:
        date - send date, can be null
        Returns:
        sent MimeMessage
        Throws:
        IOException - generally thrown by DataHandler
        javax.mail.MessagingException - for failure
      • send

        public javax.mail.internet.MimeMessage send()
                                             throws javax.mail.MessagingException,
                                                    IOException
        Send the message.
        Returns:
        sent MimeMessage
        Throws:
        IOException - generally thrown by DataHandler
        javax.mail.MessagingException - for failure