Package de.aristaflow.adept2.model.mail
Class Email
java.lang.Object
de.aristaflow.adept2.model.mail.Email
- All Implemented Interfaces:
Closeable,Serializable,AutoCloseable
A simple data structure and builder for an email. You have to set at least one
recipient, the subject and some
text content of the mail. When not using a
MailService
you will have to set the sender of the mail.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final StringThe name for an attachment if not set explicitly.protected Cleanup<IOException>The clean-up for closing theattachmentsas post-mortem task for this instance.protected LoggerThe logger for problems with attachments (rather the corresponding streams). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds the designated attachment to this mail.attachment(jakarta.activation.DataSource attSource, boolean embed) Adds the designated attachment to this mail.attachment(String fileName, UDTValue attData, boolean embed) Adds the content of the designated UDT value as attachment to this mail.attachment(String fileName, String contentType, byte[] attData, boolean embed) Adds the designated content as attachment to this mail.attachment(String fileName, String contentType, UDTValue attData, boolean embed) Adds the content of the designated UDT value as attachment to this mail.attachment(String fileName, String contentType, jakarta.activation.DataSource attSource, boolean embed) Adds the designated attachment to this mail.attachment(String fileName, String contentType, URI attSource, boolean embed) Adds the content of the designated URI as attachment to this mail.attachment(String fileName, String contentType, URL attSource, boolean embed) Adds the content of the designated URL as attachment to this mail.attachment(URI attSource, boolean embed) Adds the content of the designated URI as attachment to this mail.attachment(URL attSource, boolean embed) Adds the content of the designated URL as attachment to this mail.Sets an address to which to send a copy of the mail unaware of the other recipients.Sets an address to which to send a copy of the mail unaware of the other recipients.Sets the address to which to send problems that occur on the way of the mail to its recipient.Sets the address to which to send problems that occur on the way of the mail to its recipient.Sets an address to which to send a copy of the mail.Sets an address to which to send a copy of the mail.Removes all attachments from this mail.clearBcc()Removes all addresses to which to send copies of the mail unaware of the other recipients.Removes the address to which to send problems that occur on the way of the mail to its recipient.clearCc()Removes all addresses to which to send copies of the mail.Removes the address of the sender.Removes all additional headers from this mail.Removes the priority.Removes the address to which to reply to.clearTo()Removes all addresses to which to send the mail.voidclose()Sets the address of the sender.Sets the address and the name of the sender.Gets the files attached to the mail or an empty list.getBcc()Gets the addresses to which to send a copy of the mail unaware of the other recipients or an empty list.Gets the address to which to send problems that occur on the way of the mail to its recipient ornull.getCc()Gets the addresses to which to send a copy of the mail or an empty list.getFrom()Gets the address of the sender.Gets additional headers of the mail or an empty map.Gets the priority of this mail ornull.Gets the address to which to reply to (in case this differs from the sender) ornull.Gets the subject of the mail.getText()Gets the text content of the mail, i.getTo()Gets the addresses to which to send the mail.Adds the designated key-value-pair as additional header of this mail.Sets the content of the mail as HTML formatted text.booleanisHtml()Gets whether the text content of the mail is HTML (instead of plain text) and should be formatted appropriately.priority(int intPrio) Sets the priority.priority(EmailPriority prio) Sets the priority.Sets the priority.Sets the address to which to reply to (in case this differs from the sender).The address to which to reply to (in case this differs from the sender).Sets the subject of the mail.Sets the text content of the mail, i.Sets an address to which to send the mail.Sets an address to which to send the mail.
-
Field Details
-
ATTACHMENT_NAME
The name for an attachment if not set explicitly. Rather useless.- See Also:
-
logger
The logger for problems with attachments (rather the corresponding streams). -
cleanup
The clean-up for closing theattachmentsas post-mortem task for this instance.
-
-
Constructor Details
-
Email
Deprecated, for removal: This API element is subject to removal in a future version.UseEmail(Logger)instead.Creates a new email to be built using the corresponding builder methods. Initially the email is empty and cannot be used. -
Email
Creates a new email to be built using the corresponding builder methods. Initially the email is empty and cannot be used.- Parameters:
logger- The logger for problems with attachments (rather the corresponding streams).
-
-
Method Details
-
getFrom
Gets the address of the sender. This may benullwhen using aMailServicefor sending this mail. In this case theMailServicewill set a default sending address.- Returns:
- The address of the sender or
null.
-
getReplyTo
Gets the address to which to reply to (in case this differs from the sender) ornull.- Returns:
- The address to which to reply to (in case this differs from the sender) or
null.
-
getBounceTo
Gets the address to which to send problems that occur on the way of the mail to its recipient ornull.- Returns:
- The address to which to send problems that occur on the way of the mail to its
recipient or
null.
-
getTo
Gets the addresses to which to send the mail. This has to contain at least one valid address.- Returns:
- The addresses to which to send the mail.
-
getCc
Gets the addresses to which to send a copy of the mail or an empty list.- Returns:
- The addresses to which to send a copy of the mail or an empty list.
-
getBcc
Gets the addresses to which to send a copy of the mail unaware of the other recipients or an empty list.- Returns:
- The addresses to which to send a copy of the mail unaware of the other recipients.
-
getSubject
Gets the subject of the mail. This has to be set before sending the mail.- Returns:
- The subject of the mail.
-
getText
Gets the text content of the mail, i. e. the text mail body. This has to be set before sending the mail.- Returns:
- The text content of the mail, i. e. the text mail body. This has to be set before sending the mail.
-
isHtml
public boolean isHtml()Gets whether the text content of the mail is HTML (instead of plain text) and should be formatted appropriately.- Returns:
- Whether the text content of the mail is HTML (instead of plain text) and should be formatted appropriately.
-
getPriority
Gets the priority of this mail ornull.- Returns:
- The priority of this mail or
null.
-
getAttachments
Gets the files attached to the mail or an empty list.- Returns:
- The files attached to the mail or an empty list.
-
getHeaders
Gets additional headers of the mail or an empty map.- Returns:
- Additional headers of the mail or an empty map.
-
from
Sets the address of the sender.- Parameters:
address- The address of the sender.- Returns:
- This
Email.
-
from
Sets the address and the name of the sender.- Parameters:
name- The name of the sender.address- The address of the sender.- Returns:
- This
Email.
-
clearFrom
Removes the address of the sender.- Returns:
- This
Email.
-
replyTo
Sets the address to which to reply to (in case this differs from the sender).- Parameters:
address- The address to which to reply to.- Returns:
- This
Email.
-
replyTo
The address to which to reply to (in case this differs from the sender).- Parameters:
name- The name to which to reply to.address- The address to which to reply to.- Returns:
- This
Email.
-
clearReplyTo
Removes the address to which to reply to.- Returns:
- This
Email.
-
bounceTo
Sets the address to which to send problems that occur on the way of the mail to its recipient.- Parameters:
address- The address to which to send problems that occur on the way of the mail to its recipient.- Returns:
- This
Email.
-
bounceTo
Sets the address to which to send problems that occur on the way of the mail to its recipient.- Parameters:
name- The name to which to send problems that occur on the way of the mail to its recipient.address- The address to which to send problems that occur on the way of the mail to its recipient.- Returns:
- This
Email.
-
clearBounceTo
Removes the address to which to send problems that occur on the way of the mail to its recipient.- Returns:
- This
Email.
-
to
Sets an address to which to send the mail. At least one address has to be set before sending the mail.- Parameters:
address- An address to which to send the mail.- Returns:
- This
Email.
-
to
Sets an address to which to send the mail. At least one address has to be set before sending the mail.- Parameters:
name- A name to which to send the mail.address- An address to which to send the mail.- Returns:
- This
Email.
-
clearTo
Removes all addresses to which to send the mail.- Returns:
- This
Email.
-
cc
Sets an address to which to send a copy of the mail.- Parameters:
address- An address to which to send a copy of the mail.- Returns:
- This
Email.
-
cc
Sets an address to which to send a copy of the mail.- Parameters:
name- A name to which to send a copy of the mail.address- An address to which to send a copy of the mail.- Returns:
- This
Email.
-
clearCc
Removes all addresses to which to send copies of the mail.- Returns:
- This
Email.
-
bcc
Sets an address to which to send a copy of the mail unaware of the other recipients.- Parameters:
address- An address to which to send a copy of the mail unaware of the other recipients.- Returns:
- This
Email.
-
bcc
Sets an address to which to send a copy of the mail unaware of the other recipients.- Parameters:
name- A name to which to send a copy of the mail unaware of the other recipients.address- An address to which to send a copy of the mail unaware of the other recipients.- Returns:
- This
Email.
-
clearBcc
Removes all addresses to which to send copies of the mail unaware of the other recipients.- Returns:
- This
Email.
-
subject
Sets the subject of the mail. This has to be set before sending the mail.- Parameters:
subj- The subject of the mail.- Returns:
- This
Email.
-
text
Sets the text content of the mail, i. e. the text mail body. This has to be set before sending the mail.- Parameters:
txt- The text content of the mail, i. e. the text mail body. This has to be set before sending the mail.- Returns:
- This
Email.
-
html
Sets the content of the mail as HTML formatted text. This replacestext(String). This has to be set before sending the mail.- Parameters:
htm- The HTML formatted text content of the mail, i. e. the text mail body. This has to be set before sending the mail.- Returns:
- This
Email.
-
priority
Sets the priority.- Parameters:
intPrio- The integer value of the priority to set.- Returns:
- This
Email.
-
priority
Sets the priority.- Parameters:
strPrio- The string value of the priority to set (the same name as the constants with space instead of underscore and case-insensitive).- Returns:
- This
Email.
-
priority
Sets the priority.- Parameters:
prio- The priority to set.- Returns:
- This
Email.
-
clearPriority
Removes the priority.- Returns:
- This
Email.
-
attachment
Adds the designated attachment to this mail.- Parameters:
att- The attachment.- Returns:
- This
Email.
-
attachment
Adds the content of the designated UDT value as attachment to this mail. If the UDT name of the designated contains a/, the name will be assumed to be a valid content type and thus used appropriately. Otherwiseapplication/octet-streamwill be used as content type.- Parameters:
fileName- The file name of the attachment. This must not benullnor blank.attData- The actual content. The caller is responsible for closing.embed- Whether to embed this attachment, i. e. hiding it from the list of attachments.- Returns:
- This
Email.
-
attachment
Adds the content of the designated UDT value as attachment to this mail.- Parameters:
fileName- The file name of the attachment. This must not benullnor blank.contentType- The content type of the file. If this isnull,application/octet-streamwill be used.attData- The actual content. The caller is responsible for closing.embed- Whether to embed this attachment, i. e. hiding it from the list of attachments.- Returns:
- This
Email.
-
attachment
Adds the designated content as attachment to this mail.- Parameters:
fileName- The file name of the attachment. This must not benullnor blank.contentType- The content type of the file. If this isnull,application/octet-streamwill be used.attData- The actual content.embed- Whether to embed this attachment, i. e. hiding it from the list of attachments.- Returns:
- This
Email.
-
attachment
Adds the content of the designated URL as attachment to this mail.- Parameters:
attSource- The URL used as data source, providing name, the content type and the actual attachment content.embed- Whether to embed this attachment, i. e. hiding it from the list of attachments.- Returns:
- This
Email.
-
attachment
Adds the content of the designated URL as attachment to this mail.- Parameters:
fileName- The file name of the attachment. If this isnullor blank, default name will be used.contentType- The content type of the attachment. If this isnull,application/octet-streamwill be used.attSource- The URL from which to retrieve the content.embed- Whether to embed this attachment, i. e. hiding it from the list of attachments.- Returns:
- This
Email.
-
attachment
Adds the content of the designated URI as attachment to this mail.- Parameters:
attSource- The URI used as data source, providing name, the content type and the actual attachment content.embed- Whether to embed this attachment, i. e. hiding it from the list of attachments.- Returns:
- This
Email. - Throws:
MalformedURLException- If there are problems converting the designated URI to a URL, aMalFormedURLExceptionwill be thrown.
-
attachment
public Email attachment(String fileName, String contentType, URI attSource, boolean embed) throws MalformedURLException Adds the content of the designated URI as attachment to this mail.- Parameters:
fileName- The file name of the attachment. If this isnullor blank, default name will be used.contentType- The content type of the attachment. If this isnull,application/octet-streamwill be used.attSource- The URI from which to retrieve the content.embed- Whether to embed this attachment, i. e. hiding it from the list of attachments.- Returns:
- This
Email. - Throws:
MalformedURLException- If there are problems converting the designated URI to a URL, aMalFormedURLExceptionwill be thrown.
-
attachment
Adds the designated attachment to this mail.- Parameters:
attSource- The data source providing name, the content type and the actual attachment content.embed- Whether to embed this attachment, i. e. hiding it from the list of attachments.- Returns:
- This
Email.
-
attachment
public Email attachment(String fileName, String contentType, jakarta.activation.DataSource attSource, boolean embed) Adds the designated attachment to this mail.- Parameters:
fileName- The file name of the attachment. If this isnullor blank the name of the designated data source will be used. If this is alsonullor blank, default name will be used.contentType- The content type of the attachment. If this is notnull, it will override the content type of the designated data source.attSource- The data source providing the actual attachment content.embed- Whether to embed this attachment, i. e. hiding it from the list of attachments.- Returns:
- This
Email.
-
clearAttachments
Removes all attachments from this mail.- Returns:
- This
Email.
-
header
Adds the designated key-value-pair as additional header of this mail.- Parameters:
name- The name of the additional header.value- The value of the additional header. This may benull.- Returns:
- This
Email.
-
clearHeaders
Removes all additional headers from this mail.- Returns:
- This
Email.
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
Email(Logger)instead.