Class Mail

java.lang.Object
io.quarkus.mailer.Mail

public class Mail extends Object
Represents an e-mail. This class encapsulates the various attributes you want to set on an e-mail you are going to send (to, subject, body...).

Instances are NOT thread-safe.

  • Constructor Details

    • Mail

      public Mail()
      Creates a new instance of Mail.
  • Method Details

    • withText

      public static Mail withText(String to, String subject, String text)
      Creates a new instance of Mail that contains a "text" body. The returned instance can be modified.
      Parameters:
      to - the address of the recipient
      subject - the subject
      text - the body
      Returns:
      the new Mail instance.
    • withHtml

      public static Mail withHtml(String to, String subject, String html)
      Creates a new instance of Mail that contains a "html" body. The returned instance can be modified.
      Parameters:
      to - the address of the recipient
      subject - the subject
      html - the body
      Returns:
      the new Mail instance.
    • addBcc

      public Mail addBcc(String... bcc)
      Adds BCC recipients.
      Parameters:
      bcc - the recipients, each item must be a valid email address.
      Returns:
      the current Mail
    • addCc

      public Mail addCc(String... cc)
      Adds CC recipients.
      Parameters:
      cc - the recipients, each item must be a valid email address.
      Returns:
      the current Mail
    • addTo

      public Mail addTo(String... to)
      Adds TO recipients.
      Parameters:
      to - the recipients, each item must be a valid email address.
      Returns:
      the current Mail
    • getBcc

      public List<String> getBcc()
      Returns:
      the BCC recipients.
    • setBcc

      public Mail setBcc(List<String> bcc)
      Sets the BCC recipients.
      Parameters:
      bcc - the list of recipients
      Returns:
      the current Mail
    • getCc

      public List<String> getCc()
      Returns:
      the CC recipients.
    • setCc

      public Mail setCc(List<String> cc)
      Sets the CC recipients.
      Parameters:
      cc - the list of recipients
      Returns:
      the current Mail
    • getFrom

      public String getFrom()
      Returns:
      the sender address.
    • setFrom

      public Mail setFrom(String from)
      Sets the sender address. Notes that it's not accepted to send an email without a sender address. A default sender address can be configured in the application properties ( quarkus.mailer.from )
      Parameters:
      from - the sender address
      Returns:
      the current Mail
    • getReplyTo

      public String getReplyTo()
      Returns:
      the reply-to address. In the case of multiple addresses, the comma-separated list is returned, following the https://datatracker.ietf.org/doc/html/rfc5322#section-3.6.2 recommendation. If no reply-to address has been set, it returns null.
    • addReplyTo

      public Mail addReplyTo(String replyTo)
      Adds a reply-to address.
      Parameters:
      replyTo - the address to use as reply-to. Must be a valid email address.
      Returns:
      the current Mail
      See Also:
    • setReplyTo

      public Mail setReplyTo(String replyTo)
      Sets the reply-to address.
      Parameters:
      replyTo - the address to use as reply-to. Must be a valid email address.
      Returns:
      the current Mail
      See Also:
    • setReplyTo

      public Mail setReplyTo(String... replyTo)
      Sets the reply-to addresses.
      Parameters:
      replyTo - the addresses to use as reply-to. Must contain valid email addresses, must contain at least one address.
      Returns:
      the current Mail
    • getBounceAddress

      public String getBounceAddress()
      Returns:
      the bounce address.
    • setBounceAddress

      public Mail setBounceAddress(String bounceAddress)
      Sets the bounce address. A default sender address can be configured in the application properties ( quarkus.mailer.bounceAddress )
      Parameters:
      bounceAddress - the bounce address, must be a valid email address.
      Returns:
      the current Mail
    • getSubject

      public String getSubject()
      Returns:
      the subject
    • setSubject

      public Mail setSubject(String subject)
      Sets the email subject.
      Parameters:
      subject - the subject
      Returns:
      the current Mail
    • getText

      public String getText()
      Returns:
      the text content of the email
    • setText

      public Mail setText(String text)
      Sets the body of the email as plain text.
      Parameters:
      text - the content
      Returns:
      the current Mail
    • getHtml

      public String getHtml()
      Returns:
      the HTML content of the email
    • setHtml

      public Mail setHtml(String html)
      Sets the body of the email as HTML.
      Parameters:
      html - the content
      Returns:
      the current Mail
    • getTo

      public List<String> getTo()
      Returns:
      the TO recipients.
    • setTo

      public Mail setTo(List<String> to)
      Sets the TO recipients.
      Parameters:
      to - the list of recipients
      Returns:
      the current Mail
    • getHeaders

      public Map<String,List<String>> getHeaders()
      Returns:
      the current set of headers.
    • addHeader

      public Mail addHeader(String key, String... values)
      Adds a header value. If this header already has a value, the value is appended.
      Parameters:
      key - the header name, must not be null
      values - the header values, must not be null
      Returns:
      the current Mail
    • removeHeader

      public Mail removeHeader(String key)
      Removes a header.
      Parameters:
      key - the header name, must not be null.
      Returns:
      the current Mail
    • setHeaders

      public Mail setHeaders(Map<String,List<String>> headers)
      Sets the list of headers.
      Parameters:
      headers - the headers
      Returns:
      the current Mail
    • addInlineAttachment

      public Mail addInlineAttachment(String name, File file, String contentType, String contentId)
      Adds an inline attachment.
      Parameters:
      name - the name of the attachment, generally a file name.
      file - the file to be attached. Note that the file will be read asynchronously.
      contentType - the content type
      contentId - the content id. It must follow the <some-id@some-domain> syntax. Then the HTML content can reference this attachment using src="cid:some-id@some-domain".
      Returns:
      the current Mail
    • addAttachment

      public Mail addAttachment(String name, File file, String contentType)
      Adds an attachment.
      Parameters:
      name - the name of the attachment, generally a file name.
      file - the file to be attached. Note that the file will be read asynchronously.
      contentType - the content type.
      Returns:
      the current Mail
    • addAttachment

      public Mail addAttachment(String name, byte[] data, String contentType)
      Adds an attachment.
      Parameters:
      name - the name of the attachment, generally a file name.
      data - the binary data to be attached
      contentType - the content type.
      Returns:
      the current Mail
    • addAttachment

      public Mail addAttachment(String name, Flow.Publisher<Byte> data, String contentType)
      Adds an attachment.
      Parameters:
      name - the name of the attachment, generally a file name.
      data - the binary data to be attached
      contentType - the content type.
      Returns:
      the current Mail
    • addInlineAttachment

      public Mail addInlineAttachment(String name, byte[] data, String contentType, String contentId)
      Adds an inline attachment.
      Parameters:
      name - the name of the attachment, generally a file name.
      data - the binary data to be attached
      contentType - the content type
      contentId - the content id. It must follow the <some-id@some-domain> syntax. Then the HTML content can reference this attachment using src="cid:some-id@some-domain".
      Returns:
      the current Mail
    • addInlineAttachment

      public Mail addInlineAttachment(String name, Flow.Publisher<Byte> data, String contentType, String contentId)
      Adds an inline attachment.
      Parameters:
      name - the name of the attachment, generally a file name.
      data - the binary data to be attached
      contentType - the content type
      contentId - the content id. It must follow the <some-id@some-domain> syntax. Then the HTML content can reference this attachment using src="cid:some-id@some-domain".
      Returns:
      the current Mail
    • addAttachment

      public Mail addAttachment(String name, byte[] data, String contentType, String description, String disposition)
      Adds an attachment.
      Parameters:
      name - the name of the attachment, generally a file name.
      data - the binary data to be attached
      contentType - the content type
      description - the description of the attachment
      disposition - the disposition of the attachment
      Returns:
      the current Mail
    • addAttachment

      public Mail addAttachment(String name, Flow.Publisher<Byte> data, String contentType, String description, String disposition)
      Adds an attachment.
      Parameters:
      name - the name of the attachment, generally a file name.
      data - the binary data to be attached
      contentType - the content type
      description - the description of the attachment
      disposition - the disposition of the attachment
      Returns:
      the current Mail
    • getAttachments

      public List<Attachment> getAttachments()
      Returns:
      the list of attachments
    • setAttachments

      public Mail setAttachments(List<Attachment> attachments)
      Sets the attachment list.
      Parameters:
      attachments - the attachments.
      Returns:
      the current Mail