Package io.quarkus.mailer
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.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description MailaddAttachment(String name, byte[] data, String contentType)Adds an attachment.MailaddAttachment(String name, byte[] data, String contentType, String description, String disposition)Adds an attachment.MailaddAttachment(String name, File file, String contentType)Adds an attachment.MailaddAttachment(String name, org.reactivestreams.Publisher<Byte> data, String contentType)Adds an attachment.MailaddAttachment(String name, org.reactivestreams.Publisher<Byte> data, String contentType, String description, String disposition)Adds an attachment.MailaddBcc(String... bcc)Adds BCC recipients.MailaddCc(String... cc)Adds CC recipients.MailaddHeader(String key, String... values)Adds a header value.MailaddInlineAttachment(String name, byte[] data, String contentType, String contentId)Adds an inline attachment.MailaddInlineAttachment(String name, File file, String contentType, String contentId)Adds an inline attachment.MailaddInlineAttachment(String name, org.reactivestreams.Publisher<Byte> data, String contentType, String contentId)Adds an inline attachment.MailaddReplyTo(String replyTo)Adds a reply-to address.MailaddTo(String... to)Adds TO recipients.List<Attachment>getAttachments()List<String>getBcc()StringgetBounceAddress()List<String>getCc()StringgetFrom()Map<String,List<String>>getHeaders()StringgetHtml()StringgetReplyTo()StringgetSubject()StringgetText()List<String>getTo()MailremoveHeader(String key)Removes a header.MailsetAttachments(List<Attachment> attachments)Sets the attachment list.MailsetBcc(List<String> bcc)Sets the BCC recipients.MailsetBounceAddress(String bounceAddress)Sets the bounce address.MailsetCc(List<String> cc)Sets the CC recipients.MailsetFrom(String from)Sets the sender address.MailsetHeaders(Map<String,List<String>> headers)Sets the list of headers.MailsetHtml(String html)Sets the body of the email as HTML.MailsetReplyTo(String replyTo)Sets the reply-to address.MailsetReplyTo(String... replyTo)Sets the reply-to addresses.MailsetSubject(String subject)Sets the email subject.MailsetText(String text)Sets the body of the email as plain text.MailsetTo(List<String> to)Sets the TO recipients.static MailwithHtml(String to, String subject, String html)Creates a new instance ofMailthat contains a "html" body.static MailwithText(String to, String subject, String text)Creates a new instance ofMailthat contains a "text" body.
-
-
-
Constructor Detail
-
Mail
public Mail()
Creates a new instance ofMail.
-
-
Method Detail
-
withText
public static Mail withText(String to, String subject, String text)
Creates a new instance ofMailthat contains a "text" body. The returned instance can be modified.- Parameters:
to- the address of the recipientsubject- the subjecttext- the body- Returns:
- the new
Mailinstance.
-
withHtml
public static Mail withHtml(String to, String subject, String html)
Creates a new instance ofMailthat contains a "html" body. The returned instance can be modified.- Parameters:
to- the address of the recipientsubject- the subjecthtml- the body- Returns:
- the new
Mailinstance.
-
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
-
setBcc
public Mail setBcc(List<String> bcc)
Sets the BCC recipients.- Parameters:
bcc- the list of recipients- Returns:
- the current
Mail
-
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(String)
-
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(String[])
-
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
-
setTo
public Mail setTo(List<String> to)
Sets the TO recipients.- Parameters:
to- the list of recipients- Returns:
- the current
Mail
-
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 benullvalues- the header values, must not benull- Returns:
- the current
Mail
-
removeHeader
public Mail removeHeader(String key)
Removes a header.- Parameters:
key- the header name, must not benull.- 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 typecontentId- the content id. It must follow the<some-id@some-domain>syntax. Then the HTML content can reference this attachment usingsrc="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 attachedcontentType- the content type.- Returns:
- the current
Mail
-
addAttachment
public Mail addAttachment(String name, org.reactivestreams.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 attachedcontentType- 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 attachedcontentType- the content typecontentId- the content id. It must follow the<some-id@some-domain>syntax. Then the HTML content can reference this attachment usingsrc="cid:some-id@some-domain".- Returns:
- the current
Mail
-
addInlineAttachment
public Mail addInlineAttachment(String name, org.reactivestreams.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 attachedcontentType- the content typecontentId- the content id. It must follow the<some-id@some-domain>syntax. Then the HTML content can reference this attachment usingsrc="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 attachedcontentType- the content typedescription- the description of the attachmentdisposition- the disposition of the attachment- Returns:
- the current
Mail
-
addAttachment
public Mail addAttachment(String name, org.reactivestreams.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 attachedcontentType- the content typedescription- the description of the attachmentdisposition- 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
-
-