- All Known Implementing Classes:
MailMessageImpl
- Author:
- Besmir Beqiri
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddAttachment(File file) Adds aFileas an attachment to this message.voidaddAttachment(File file, String cid) Adds aFileas an attachment to this message with the given content ID.voidaddAttachment(File file, String contentType, String encoding) Adds aFileas an attachment to this message with the given content type and encoding.voidAdd these addresses to the existing "Bcc" attribute.voidAdd these addresses to the existing "Cc" attribute.voidAdd these addresses to the existing "From" attribute.voidAdd these addresses to the existing "To" attribute.static @NotNull MailMessagecreate(MailClient mailClient) Creates a new MailMessage instance using the provided MailClient.org.eclipse.collections.api.list.ImmutableList<String> Get all the recipients of this message.org.eclipse.collections.api.list.ImmutableList<String> getBcc()Return the "Bcc" attribute addresses.org.eclipse.collections.api.list.ImmutableList<String> getCc()Return the "Cc" attribute addresses.org.eclipse.collections.api.list.ImmutableList<String> getFrom()Returns the "From" attribute addresses.Get the date this message was received.org.eclipse.collections.api.list.ImmutableList<String> Get the addresses to which replies should be directed.Get the date this message was sent.Get the subject of this message.org.eclipse.collections.api.list.ImmutableList<String> getTo()Returns the "To" attribute addresses.Save any changes made to this message into the message-store when the containing folder is closed, if the message is contained in a folder.send()Send a message.Send the message to the specified addresses, ignoring any recipients specified in the message itself.voidSet the "Bcc" attribute addresses in this message.voidSet the "Cc" attribute addresses in this message.voidSet the "From" attribute address in this message.voidA convenience method that sets the given String as this part's content with a MIME type of "text/html".voidsetReplyTo(org.eclipse.collections.api.list.ImmutableList<String> addresses) Set the addresses to which replies should be directed.voidsetSentDate(Instant instant) Set the sent date of this message.voidsetSubject(String subject) Set the subject of this message.voidA convenience method that sets the given String as this part's content with a MIME type of "text/plain".voidSet the "To" attribute address in this message.voidSet the "To" attribute addresses in this message.
-
Method Details
-
create
Creates a new MailMessage instance using the provided MailClient.This is a factory method that delegates the creation of the MailMessage instance to the provided MailClient. The MailClient is expected to implement the logic for creating a new MailMessage.
- Parameters:
mailClient- theMailClientthat will create theMailMessage- Returns:
- a new MailMessage instance
-
getFrom
org.eclipse.collections.api.list.ImmutableList<String> getFrom()Returns the "From" attribute addresses. The "From" attribute contains the identity of the person(s) who wished this message to be sent.This method returns
nullif this attribute is not present in this message. Returns an empty array if this attribute is present, but contains no addresses.- Returns:
- immutable list of Strings containing the addresses of the sender
- Throws:
MailException- if the sender address fails to be retrieved
-
setFrom
Set the "From" attribute address in this message.- Parameters:
address- the sender address- Throws:
MailException- if the sender address fails to be set
-
addFrom
Add these addresses to the existing "From" attribute.- Parameters:
addresses- the sender addresses- Throws:
MailException- if the sender addresses fail to be added
-
getTo
org.eclipse.collections.api.list.ImmutableList<String> getTo()Returns the "To" attribute addresses. The "To" attribute contains the primary recipients of this message.This method returns
nullif this attribute is not present in this message. Returns an empty array if this attribute is present, but contains no addresses.- Returns:
- immutable list of Strings containing the addresses of the primary recipients
- Throws:
MailException- if the primary recipient addresses fail to be retrieved
-
setTo
Set the "To" attribute address in this message.- Parameters:
address- the primary recipient address- Throws:
MailException- if the primary recipient address fail to be set
-
setTo
Set the "To" attribute addresses in this message.- Parameters:
addresses- the primary recipient addresses- Throws:
MailException- if the primary recipient addresses fail to be set
-
addTo
Add these addresses to the existing "To" attribute.- Parameters:
addresses- the primary recipient addresses- Throws:
MailException- if the primary recipient addresses fail to be added
-
getCc
org.eclipse.collections.api.list.ImmutableList<String> getCc()Return the "Cc" attribute addresses. The "Cc" attribute contains secondary recipients of this message.This method returns
nullif this attribute is not present in this message. Returns an empty array if this attribute is present, but contains no addresses.- Returns:
- immutable list of Strings containing the addresses of the secondary recipients
- Throws:
MailException- if the secondary recipient addresses fail to be retrieved
-
setCc
Set the "Cc" attribute addresses in this message.- Parameters:
addresses- the secondary recipient addresses- Throws:
MailException- if the secondary recipient addresses fail to be set
-
addCc
Add these addresses to the existing "Cc" attribute.- Parameters:
addresses- the secondary recipient addresses- Throws:
MailException- if the secondary recipient addresses fail to be added
-
getBcc
org.eclipse.collections.api.list.ImmutableList<String> getBcc()Return the "Bcc" attribute addresses. The "Bcc" attribute contains tertiary recipients of this message.This method returns
nullif this attribute is not present in this message. Returns an empty array if this attribute is present, but contains no addresses.- Returns:
- immutable list of Strings containing the addresses of the tertiary recipients
- Throws:
MailException- if the tertiary recipient addresses fail to be retrieved
-
setBcc
Set the "Bcc" attribute addresses in this message.- Parameters:
addresses- the tertiary recipient addresses- Throws:
MailException- if the tertiary recipient addresses fail to be set
-
addBcc
Add these addresses to the existing "Bcc" attribute.- Parameters:
addresses- the tertiary recipient addresses- Throws:
MailException- if the tertiary recipient addresses fail to be added
-
getAllRecipients
org.eclipse.collections.api.list.ImmutableList<String> getAllRecipients()Get all the recipients of this message. This method returnsnullif the corresponding header is not present. Returns an empty array if the header is present, but contains no addresses.- Returns:
- all the recipients of this message
- Throws:
MailException- if the recipients fail to be retrieved
-
getReplyTo
org.eclipse.collections.api.list.ImmutableList<String> getReplyTo()Get the addresses to which replies should be directed. This will usually be the sender of the message, but some messages may direct replies to a different address.The default implementation simply calls the
getFrommethod.This method returns
nullif the corresponding header is not present. Returns an empty array if the header is present, but contains no addresses.- Returns:
- addresses to which replies should be directed
- Throws:
MailException- if the reply-to addresses fail to be retrieved- See Also:
-
setReplyTo
Set the addresses to which replies should be directed. (Normally only a single address will be specified.) Not all message types allow this to be specified separately from the sender of the message.The default implementation provided here just throws the MethodNotSupportedException.
- Parameters:
addresses- addresses to which replies should be directed- Throws:
MailException- if the reply-to addresses fail to be set
-
getSubject
String getSubject()Get the subject of this message.- Returns:
- the subject string
- Throws:
MailException- if the subject fails to be retrieved
-
setSubject
Set the subject of this message.- Parameters:
subject- the subject string- Throws:
MailException- if the subject fails to be set
-
setText
A convenience method that sets the given String as this part's content with a MIME type of "text/plain".- Parameters:
text- the text that is the message's content- Throws:
MailException- if the text fails to be set
-
setHtml
A convenience method that sets the given String as this part's content with a MIME type of "text/html".- Parameters:
htmlText- the html content that is the message's content- Throws:
MailException- if the html content fails to be set
-
addAttachment
Adds aFileas an attachment to this message.- Parameters:
file- the file to attach- Throws:
MailException- if an error occurs while attaching the file
-
addAttachment
Adds aFileas an attachment to this message with the given content ID.- Parameters:
file- the file to attachcid- the "Content-ID" of the attachment- Throws:
MailException- if an error occurs while attaching the file
-
addAttachment
Adds aFileas an attachment to this message with the given content type and encoding.- Parameters:
file- the file to attachcontentType- the content type of the fileencoding- the encoding of the file- Throws:
MailException- if an error occurs while attaching the file
-
getSentDate
Instant getSentDate()Get the date this message was sent.- Returns:
- the instant this message was sent
- Throws:
MailException- if the sent date fails to be retrieved
-
setSentDate
Set the sent date of this message.- Parameters:
instant- the instant this message was sent- Throws:
MailException- if the sent date fails to be set
-
getReceivedDate
Instant getReceivedDate()Get the date this message was received.- Returns:
- the instant this message was received
- Throws:
MailException- if the received date fails to be retrieved
-
saveChanges
CompletableFuture<Void> saveChanges()Save any changes made to this message into the message-store when the containing folder is closed, if the message is contained in a folder. Update any header fields to be consistent with the changed message contents. If any part of a message's headers or contents are changed, this method must be called to ensure that those changes are permanent. If this method is not called, any such modifications may or may not be saved, depending on the message store and folder implementation.Messages obtained from folders opened READ_ONLY should not be modified and
saveChangesshould not be called on such messages.- Returns:
- a
CompletableFuturethat completes when the changes are saved - Throws:
MailException- if the changes fail to be saved
-
send
CompletableFuture<Void> send()Send a message. The message will be sent to all recipient addresses specified in the message (as returned from the methodgetAllRecipients()), using message transports appropriate to each address. Thesendmethod calls thesaveChangesmethod on the message before sending it.In typical usage, a
MailExceptionreflects an error detected by the server. The details of theMailExceptionwill usually contain the error message from the server (such as an SMTP error message). An address may be detected as invalid for a variety of reasons - the address may not exist, the address may have invalid syntax, the address may have exceeded its quota, etc.- Returns:
- a
CompletableFuturethat completes when the message is sent - Throws:
MailException- if the message fails to be sent- See Also:
-
send
Send the message to the specified addresses, ignoring any recipients specified in the message itself. Thesendmethod calls thesaveChangesmethod on the message before sending it.- Parameters:
addresses- the addresses to which to send the message- Returns:
- a
CompletableFuturethat completes when the message is sent - Throws:
MailException- if the message fails to be sent- See Also:
-