Class MailBuilder

java.lang.Object
com.axelor.mail.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 Details

    • MailBuilder

      public MailBuilder(jakarta.mail.Session session)
  • Method Details

    • subject

      public MailBuilder subject(String subject)
    • to

      public MailBuilder to(String... recipients)
    • cc

      public MailBuilder cc(String... recipients)
    • bcc

      public MailBuilder bcc(String... recipients)
    • replyTo

      public MailBuilder replyTo(String... recipients)
    • from

      public MailBuilder from(String from)
    • sender

      public MailBuilder sender(String sender)
    • header

      public MailBuilder header(String name, String value)
    • text

      public MailBuilder text(String text)
    • html

      public MailBuilder html(String text)
    • attach

      public MailBuilder attach(String name, String link)
    • 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 jakarta.mail.internet.MimeMessage build() throws jakarta.mail.MessagingException, IOException
      Build a new MimeMessage instance from the provided details.
      Returns:
      an instance of MimeMessage
      Throws:
      IOException - generally thrown by DataHandler
      jakarta.mail.MessagingException - for failure
    • build

      public jakarta.mail.internet.MimeMessage build(String messageId) throws jakarta.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
      jakarta.mail.MessagingException - for failure
    • send

      public jakarta.mail.internet.MimeMessage send(Date date) throws jakarta.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
      jakarta.mail.MessagingException - for failure
    • send

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