Package io.quarkus.mailer
Class Mail
java.lang.Object
io.quarkus.mailer.Mail
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddAttachment(String name, byte[] data, String contentType) Adds an attachment.addAttachment(String name, byte[] data, String contentType, String description, String disposition) Adds an attachment.addAttachment(String name, File file, String contentType) Adds an attachment.addAttachment(String name, Flow.Publisher<Byte> data, String contentType) Adds an attachment.addAttachment(String name, Flow.Publisher<Byte> data, String contentType, String description, String disposition) Adds an attachment.Adds BCC recipients.Adds CC recipients.Adds a header value.addInlineAttachment(String name, byte[] data, String contentType, String contentId) Adds an inline attachment.addInlineAttachment(String name, File file, String contentType, String contentId) Adds an inline attachment.addInlineAttachment(String name, Flow.Publisher<Byte> data, String contentType, String contentId) Adds an inline attachment.addReplyTo(String replyTo) Adds a reply-to address.Adds TO recipients.getBcc()getCc()getFrom()getHtml()getText()getTo()removeHeader(String key) Removes a header.setAttachments(List<Attachment> attachments) Sets the attachment list.Sets the BCC recipients.setBounceAddress(String bounceAddress) Sets the bounce address.Sets the CC recipients.Sets the sender address.setHeaders(Map<String, List<String>> headers) Sets the list of headers.Sets the body of the email as HTML.setReplyTo(String replyTo) Sets the reply-to address.setReplyTo(String... replyTo) Sets the reply-to addresses.setSubject(String subject) Sets the email subject.Sets the body of the email as plain text.Sets the TO recipients.static MailCreates a new instance ofMailthat contains a "html" body.static MailCreates a new instance ofMailthat contains a "text" body.
-
Constructor Details
-
Mail
public Mail()Creates a new instance ofMail.
-
-
Method Details
-
withText
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
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
Adds BCC recipients.- Parameters:
bcc- the recipients, each item must be a valid email address.- Returns:
- the current
Mail
-
addCc
Adds CC recipients.- Parameters:
cc- the recipients, each item must be a valid email address.- Returns:
- the current
Mail
-
addTo
Adds TO recipients.- Parameters:
to- the recipients, each item must be a valid email address.- Returns:
- the current
Mail
-
getBcc
- Returns:
- the BCC recipients.
-
setBcc
Sets the BCC recipients.- Parameters:
bcc- the list of recipients- Returns:
- the current
Mail
-
getCc
- Returns:
- the CC recipients.
-
setCc
Sets the CC recipients.- Parameters:
cc- the list of recipients- Returns:
- the current
Mail
-
getFrom
- Returns:
- the sender address.
-
setFrom
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
- 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
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
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
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
- Returns:
- the bounce address.
-
setBounceAddress
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
- Returns:
- the subject
-
setSubject
Sets the email subject.- Parameters:
subject- the subject- Returns:
- the current
Mail
-
getText
- Returns:
- the text content of the email
-
setText
Sets the body of the email as plain text.- Parameters:
text- the content- Returns:
- the current
Mail
-
getHtml
- Returns:
- the HTML content of the email
-
setHtml
Sets the body of the email as HTML.- Parameters:
html- the content- Returns:
- the current
Mail
-
getTo
- Returns:
- the TO recipients.
-
setTo
Sets the TO recipients.- Parameters:
to- the list of recipients- Returns:
- the current
Mail
-
getHeaders
- Returns:
- the current set of headers.
-
addHeader
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
Removes a header.- Parameters:
key- the header name, must not benull.- Returns:
- the current
Mail
-
setHeaders
Sets the list of headers.- Parameters:
headers- the headers- Returns:
- the current
Mail
-
addInlineAttachment
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
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
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
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
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, 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 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, 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 attachedcontentType- the content typedescription- the description of the attachmentdisposition- the disposition of the attachment- Returns:
- the current
Mail
-
getAttachments
- Returns:
- the list of attachments
-
setAttachments
Sets the attachment list.- Parameters:
attachments- the attachments.- Returns:
- the current
Mail
-