public class EmailMessage
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
bodyMimeType
The mime type of the body, as
|
protected javax.mail.Message |
message
The actual message
|
protected javax.mail.BodyPart |
messageBody
The body for the message
|
protected javax.mail.Multipart |
messageContent
The container for the body, attachments, etc...
|
Modifier | Constructor and Description |
---|---|
protected |
EmailMessage(javax.mail.Session session)
Build a message that is from the specified session
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
addAttachment(byte[] file,
MimeType mimeType,
java.lang.String fileName)
Adds an attachment to the message.
|
java.lang.String |
addAttachment(byte[] file,
MimeType mimeType,
java.lang.String contentId,
java.lang.String fileName)
Adds an attachment to the message.
|
java.lang.String |
addAttachment(byte[] file,
java.lang.String mimeType,
java.lang.String contentId,
java.lang.String fileName)
Adds an attachment to the message.
|
java.lang.String |
addAttachment(java.io.File file)
Adds an attachment to the message.
|
java.lang.String |
addAttachment(java.io.File file,
MimeType mimeType)
Adds an attachment to the message.
|
java.lang.String |
addAttachment(java.io.File file,
MimeType mimeType,
java.lang.String contentId)
Adds an attachment to the message.
|
java.lang.String |
addAttachment(java.io.File file,
java.lang.String mimeType)
Adds an attachment to the message.
|
java.lang.String |
addAttachment(java.io.File file,
java.lang.String mimeType,
java.lang.String contentId)
Adds an attachment to the message.
|
void |
addBccRecipient(java.lang.String emailAddress)
Add a recipient in the BCC: field
|
void |
addBccRecipients(java.util.Collection<java.lang.String> addresses)
Add a set of recipients in the BCC: field
|
void |
addCcRecipient(java.lang.String emailAddress)
Add a recipient in the CC: field
|
void |
addCcRecipients(java.util.Collection<java.lang.String> addresses)
Add a set of recipients in the CC: field
|
void |
addHeader(java.lang.String headerName,
java.lang.String headerValue)
Adds custom headers to the message
|
void |
addReplyTo(java.util.Collection<java.lang.String> emailAddresses)
Adds a collection of Reply-To values for the email
|
void |
addReplyTo(java.lang.String emailAddress)
Adds a Reply-To value for the email
|
void |
addToRecipient(java.lang.String emailAddress)
Add a recipient in the TO: field
|
void |
addToRecipients(java.util.Collection<java.lang.String> addresses)
Add a set of recipients in the TO: field
|
void |
appendImageToBody(java.io.File image)
Appends an image to the body of the email.
|
void |
appendToBody(java.lang.String addendum)
Appends the given text to the current content of the body.
|
void |
attachAllFilesInDirectory(java.io.File directory,
boolean includeSubdirectories)
Adds all files in the current directory as attachments.
|
java.lang.String |
generateUniqueContentID()
Generates a unique content ID value that can be used for attachments
|
java.util.Set<javax.mail.BodyPart> |
getAttachments()
Returns a set of the attachments included in this email
|
java.util.Set<java.lang.String> |
getBccRecipients()
Returns a set of all the recipients this message was addressed to in the 'BCC' field
|
java.util.Set<java.lang.String> |
getCcRecipients()
Returns a set of all the recipients this message was addressed to in the 'CC' field
|
java.util.List<java.lang.String> |
getFrom()
Returns a list of addresses this message is from
|
java.util.List<java.lang.String> |
getReplyTo()
Returns a list of addresses this message should be replied to at
|
java.lang.String |
getSubject()
Returns the subject of the email message
|
java.util.Set<java.lang.String> |
getToRecipients()
Returns a set of all the recipients this message was addressed to in the 'TO' field
|
void |
setBody(java.lang.String body)
Sets the body content of the message.
|
void |
setBody(java.lang.String body,
MimeType mimeType)
Sets the body content of the message.
|
void |
setBody(java.lang.String body,
java.lang.String mimeType)
Sets the body content of the message.
|
void |
setFrom(java.lang.String emailAddress)
Sets the From value for the email
|
void |
setSubject(java.lang.String subject)
Sets the subject of the message
|
protected javax.mail.Message message
protected javax.mail.Multipart messageContent
@Nullable protected javax.mail.BodyPart messageBody
@Nullable protected java.lang.String bodyMimeType
protected EmailMessage(javax.mail.Session session)
session
- The mail session used for sending email, or the session the message was received onpublic void addHeader(java.lang.String headerName, java.lang.String headerValue) throws javax.mail.MessagingException
headerName
- The name of the headerheaderValue
- The value for the headerjavax.mail.MessagingException
- On error adding to the messagepublic void addToRecipients(@NotNull java.util.Collection<java.lang.String> addresses) throws javax.mail.MessagingException
addresses
- The email addresses to addjavax.mail.MessagingException
- On invalid addresspublic void addToRecipient(@NotNull java.lang.String emailAddress) throws javax.mail.MessagingException
emailAddress
- The email address to addjavax.mail.MessagingException
- On invalid addresspublic void addCcRecipients(@NotNull java.util.Collection<java.lang.String> addresses) throws javax.mail.MessagingException
addresses
- The email addresses to addjavax.mail.MessagingException
- On invalid addresspublic void addCcRecipient(@NotNull java.lang.String emailAddress) throws javax.mail.MessagingException
emailAddress
- The email address to addjavax.mail.MessagingException
- On invalid addresspublic void addBccRecipients(@NotNull java.util.Collection<java.lang.String> addresses) throws javax.mail.MessagingException
addresses
- The email addresses to addjavax.mail.MessagingException
- On invalid addresspublic void addBccRecipient(@NotNull java.lang.String emailAddress) throws javax.mail.MessagingException
emailAddress
- The email address to addjavax.mail.MessagingException
- On invalid addresspublic void setFrom(@NotNull java.lang.String emailAddress) throws javax.mail.MessagingException
emailAddress
- The email address this message is fromjavax.mail.MessagingException
- On an invalid addresspublic void addReplyTo(@NotNull java.util.Collection<java.lang.String> emailAddresses) throws javax.mail.MessagingException
emailAddresses
- The collection of email address to addjavax.mail.MessagingException
- On an invalid addresspublic void addReplyTo(@NotNull java.lang.String emailAddress) throws javax.mail.MessagingException
emailAddress
- The email address to addjavax.mail.MessagingException
- On an invalid addresspublic void setSubject(java.lang.String subject) throws javax.mail.MessagingException
subject
- The subject of the messagejavax.mail.MessagingException
- On any error setting the message fieldpublic void setBody(java.lang.String body) throws javax.mail.MessagingException
body
- The content of the body, in HTMLjavax.mail.MessagingException
- On any error setting the message fieldpublic void setBody(java.lang.String body, @NotNull MimeType mimeType) throws javax.mail.MessagingException
body
- The content of the body, in the given typemimeType
- The Mime Type of the body contentjavax.mail.MessagingException
- On any error setting the message fieldpublic void setBody(java.lang.String body, java.lang.String mimeType) throws javax.mail.MessagingException
body
- The content of the body, in the given typemimeType
- The Mime Type of the body contentjavax.mail.MessagingException
- On any error setting the message fieldpublic void appendImageToBody(@NotNull java.io.File image) throws java.io.IOException, javax.mail.MessagingException
image
- The image to addjavax.mail.MessagingException
- On any error setting the message fieldjava.io.IOException
- On an error reading the file, or reading the current email bodypublic void appendToBody(java.lang.String addendum) throws java.io.IOException, javax.mail.MessagingException
addendum
- The text to append to the current message bodyjavax.mail.MessagingException
- On any error setting the message fieldjava.io.IOException
- On an error reading the current email bodypublic void attachAllFilesInDirectory(@NotNull java.io.File directory, boolean includeSubdirectories) throws java.io.IOException, javax.mail.MessagingException
directory
- The directory to search for files to attachincludeSubdirectories
- True to also include subdirectories, false to only include files in the immediate directoryjava.io.IOException
- On an error reading any of the files or directoriesjavax.mail.MessagingException
- On an error attaching one of the files to the messagepublic java.lang.String addAttachment(@NotNull java.io.File file) throws javax.mail.MessagingException, java.io.IOException
file
- The file to attachjavax.mail.MessagingException
- On any error setting the message fieldjava.io.IOException
- On error reading the given filepublic java.lang.String addAttachment(@NotNull java.io.File file, @NotNull MimeType mimeType) throws javax.mail.MessagingException, java.io.IOException
file
- The file to attachmimeType
- The Mime type of the filejavax.mail.MessagingException
- On any error setting the message fieldjava.io.IOException
- On error reading the given filepublic java.lang.String addAttachment(@NotNull java.io.File file, java.lang.String mimeType) throws javax.mail.MessagingException, java.io.IOException
file
- The file to attachmimeType
- The Mime type of the filejavax.mail.MessagingException
- On any error setting the message fieldjava.io.IOException
- On error reading the given filepublic java.lang.String addAttachment(@NotNull java.io.File file, @NotNull MimeType mimeType, java.lang.String contentId) throws javax.mail.MessagingException, java.io.IOException
file
- The file to attachmimeType
- The Mime type of the filecontentId
- The content ID to use for the attached file. This will match the value returned by the methodjavax.mail.MessagingException
- On any error setting the message fieldjava.io.IOException
- On error reading the given filepublic java.lang.String addAttachment(@NotNull java.io.File file, java.lang.String mimeType, java.lang.String contentId) throws javax.mail.MessagingException, java.io.IOException
file
- The file to attachmimeType
- The Mime type of the filecontentId
- The content ID to use for the attached file. This will match the value returned by the methodjavax.mail.MessagingException
- On any error setting the message fieldjava.io.IOException
- On error reading the given filepublic java.lang.String addAttachment(byte[] file, @NotNull MimeType mimeType, java.lang.String fileName) throws javax.mail.MessagingException
file
- The bytes that represent the filemimeType
- The Mime type of the filefileName
- The name to give the attached filejavax.mail.MessagingException
- On any error setting the message fieldpublic java.lang.String addAttachment(byte[] file, @NotNull MimeType mimeType, java.lang.String contentId, java.lang.String fileName) throws javax.mail.MessagingException
file
- The bytes that represent the filemimeType
- The Mime type of the filecontentId
- The content ID to use for the attached file. This will match the content ID returned by this methodfileName
- The name to give the attached filejavax.mail.MessagingException
- On any error setting the message fieldpublic java.lang.String addAttachment(byte[] file, java.lang.String mimeType, java.lang.String contentId, java.lang.String fileName) throws javax.mail.MessagingException
file
- The bytes that represent the filemimeType
- The Mime type of the filecontentId
- The content ID to use for the attached file. This will match the content ID returned by this methodfileName
- The name to give the attached filejavax.mail.MessagingException
- On any error setting the message field@NotNull public java.lang.String generateUniqueContentID()
@NotNull public java.util.Set<java.lang.String> getToRecipients()
@NotNull public java.util.Set<java.lang.String> getCcRecipients()
@NotNull public java.util.Set<java.lang.String> getBccRecipients()
@NotNull public java.util.List<java.lang.String> getFrom()
@NotNull public java.util.List<java.lang.String> getReplyTo()
@Nullable public java.lang.String getSubject()
@NotNull public java.util.Set<javax.mail.BodyPart> getAttachments()