public class EmailMessage extends Object
This class is implemented in a way to make creating of email messages as much simple and convenient as possible that is very important within RPA process. It provides different ways of defining email message parameters:
1. In one line of code. This way allows dynamically build email message and avoid the overloading of RPA process code.
new EmailMessage().recipients("tom@example.com").subject("Test email").text("This message was sent by robot.");
2. In configuration parameters. Almost all parameters of email message can be specified in configuration parameters of RPA process. It allows to remove from RPA process code definition of constant parameters.
In configuration parameters:
email.recipients=tom@example.com
email.subject=Test email
Since recipients and subject are already defined in configuration parameters they automatically will be set to any
new email message:
EmailMessage msg = new EmailMessage().text("This message was sent by robot.");
assert "Test email".equals(msg.getSubject()); //is true.
If necessary to define configuration parameters for specific emails the special parameter typeName
can be used. In the following example the typeName="user.email":
user.email.recipients=tom@example.com
user.email.subject=This is a user email
And in the code:
EmailMessage userMsg = new EmailMessage("user.email").text("This message was sent by robot.");
assert "This is a user email".equals(userMsg.getSubject()); //is true
//But
EmailMessage msg = new EmailMessage().text("This message was sent by robot.");
assert "This is a user email".equals(msg.getSubject()); //is false
assert "".equals(msg.getSubject()); //is true
3. From JSON. This way is recommended to use when it's necessary to transfer email message somewhere as text, e.g. between steps of the RPA process.
EmailMessage msg = new EmailMessage().subject("Test email").text("This message was sent by robot.");
String msgJson = msg.toJson(false);
...
EmailMessage restoredMsg = EmailMessage.fromJson(msgJson);
assert "Test email".equals(restoredMsg.getSubject()); //is true.
| Modifier and Type | Field and Description |
|---|---|
protected List<EmailAttachment> |
attachments
List of attachments attached to this email message.
|
protected List<EmailAddress> |
bccRecipients
List of email addresses who are BCC recipients of this email message.
|
protected List<EmailBodyPart> |
bodyParts
List of parts that constituents the body of this email message.
|
protected Map<String,Object> |
bodyProperties
Map with properties used for substitution of variables within the body of this email message.
|
protected List<EmailAddress> |
ccRecipients
List of email addresses who are CC recipients of this email message.
|
protected String |
charset
Charset of this email message body.
|
protected Date |
date
The received or sent date of this email.
|
protected EmailSender |
emailSender
Link to the
EmailSender that can be used for sending of this email message using method send()
and retrieving of parameters that are not specified explicitly. |
protected EmailMessage |
forwardedMessage
Link to the email message that this email message forwards.
|
protected EmailAddress |
from
Email address displayed in the filed
From: of this email message. |
protected Map<String,String> |
headers
Map with all header parameters of this email message.
|
protected String |
html
Cached HTML representation of this email message body.
|
protected String |
id
The unique identifier of this email message within mailbox.
|
protected Boolean |
isRead
Read/unread flag of this email message.
|
protected String |
parentFolder
The name of mailbox folder where this email message is contained.
|
protected List<EmailAddress> |
recipients
List of email addresses who are recipients of this email message.
|
protected EmailMessage |
replyOnMessage
Link to the email message that this email message replies on.
|
protected List<EmailAddress> |
replyTo
List of email addresses who are supposed recipients of the replying on this email message.
|
protected EmailAddress |
sender
Email address of the actual sender of this email message that corresponds to email account on behalf of which
this message is sent.
|
protected String |
senderName
Display name of the actual sender of this email message.
|
protected String |
subject
Subject of this email message.
|
protected String |
text
Cached text representation of this email message body.
|
protected String |
typeName
The name of type of this email message that defines names of configuration parameters containing related to
this email message parameters.
|
static String |
USED_DATE_TME_FORMAT_PATTERN
Date time format used for serialization/deserialization of
date field. |
| Constructor and Description |
|---|
EmailMessage()
Constructs a new instance of EmailMessage with default type name.
|
EmailMessage(EmailSender emailSender)
Constructs a new instance of EmailMessage with default type name and providing of email sender.
|
EmailMessage(String typeName)
Constructs a new instance of EmailMessage with given type name.
|
EmailMessage(String typeName,
EmailSender emailSender)
Constructs a new instance of EmailMessage with given type name and providing of email sender.
|
| Modifier and Type | Method and Description |
|---|---|
EmailMessage |
addHtml(String html)
Adds given HTML string as HTML body part of this email message.
|
EmailMessage |
addText(String text)
Adds given text string as text body part of this email message.
|
EmailMessage |
attach(File file)
Attaches given file to this email message.
|
EmailMessage |
attach(Path filePath)
Attaches given file to this email message.
|
EmailMessage |
attach(String fileName,
InputStream fileContent,
String mimeType)
Attaches given file content as attachment to this email message.
|
EmailMessage |
bccRecipients(String... recipientsSequence)
Sets explicitly email addresses who are BCC recipients of this email message.
|
protected void |
beforeSend()
Performs some preparation steps before sending of this email message.
|
EmailMessage |
ccRecipients(String... recipientsSequence)
Sets explicitly email addresses who are CC recipients of this email message.
|
EmailMessage |
charset(String charset)
Sets explicitly the charset of this email message body.
|
EmailMessage |
excludeFromCcRecipients(String... recipientsSequence)
Excludes given email addresses from the list of CC recipients of this email message.
|
EmailMessage |
excludeFromRecipients(String... recipientsSequence)
Excludes given email addresses from the list of recipients of this email message.
|
EmailMessage |
forwardMessage(boolean withAttachments)
Generates a new email message that is a forwarding of this email message.
|
EmailMessage |
from(String fromAddress)
Sets explicitly the email address displayed in the field
From: of this email message. |
static EmailMessage |
fromJson(String json)
Deserializes the email message from JSON.
|
List<EmailAttachment> |
getAttachments()
Gets attachments attached to this email message.
|
List<EmailAddress> |
getBccRecipients()
Gets list of email addresses who are BCC recipients of this email message.
|
List<EmailBodyPart> |
getBodyParts()
Gets the list of parts that constituents the body of this email message.
|
Map<String,Object> |
getBodyProperties()
Gets properties used for substitution of variables within the body of this email message.
|
List<EmailAddress> |
getCcRecipients()
Gets list of email addresses who are CC recipients of this email message.
|
String |
getCharset()
Gets charset of this email message body.
|
protected String |
getConfigParam(String template)
Gets value of configuration parameter specified in the RPA platform by the key that depends on the actual
value of
typeName. |
Date |
getDate()
Gets the date of this email message.
|
ZonedDateTime |
getDateTime()
Gets the date of this email message.
|
EmailMessage |
getForwardedMessage()
Gets the email message that this email message forwards.
|
EmailAddress |
getFrom()
Gets email address displayed in the field
From: of this email message. |
Map<String,String> |
getHeaders()
Gets key-value map with all header parameters of this email message.
|
String |
getHtml()
Gets HTML representation of this email message body.
|
String |
getId()
Gets unique identifier of this email message within mailbox.
|
String |
getParentFolder()
Gets the name of mailbox folder where this email message is contained.
|
List<EmailAddress> |
getRecipients()
Gets list of email addresses who are recipients of this email message.
|
EmailMessage |
getReplyOnMessage()
Gets the email message that this email message replies on.
|
List<EmailAddress> |
getReplyTo()
Gets list of email addresses who are supposed recipients of the replying on this email message.
|
EmailAddress |
getSender()
Gets email address of the actual sender of this email message.
|
String |
getSenderName()
Gets the display name of the actual sender of this email message.
|
String |
getSubject()
Gets subject of this email message.
|
String |
getText()
Gets text representation of this email message body.
|
boolean |
hasAttachments()
Checks whether this email message has attached files.
|
boolean |
hasHtml()
Checks whether body parts of this email message has html parts.
|
boolean |
hasText()
Checks whether body parts of this email message has text parts.
|
EmailMessage |
header(String key,
String value)
Sets header parameter for this email message.
|
EmailMessage |
html(String html)
Sets given HTML string as body of this email message.
|
boolean |
isRead()
Gets the value of read/unread flag of this email message.
|
boolean |
isUnread()
Gets the value of read/unread flag of this email message.
|
EmailMessage |
markRead()
Marks this email message as read.
|
EmailMessage |
markUnread()
Marks this email message as unread.
|
EmailMessage |
property(String key,
Object value)
Puts a new property into the properties map used for substitution of variables within the body of this
email message.
|
EmailMessage |
recipients(String... recipientsSequence)
Sets explicitly email addresses who are recipients of this email message.
|
EmailMessage |
replyAllMessage(boolean withAttachments)
Generates a new email message that is a replying to all recipients of this email message.
|
EmailMessage |
replyMessage(boolean withAttachments)
Generates a new email message that is a replying on this email message.
|
EmailMessage |
replyTo(String... recipientsSequence)
Sets explicitly email addresses who are supposed recipients of the replying on this email message.
|
void |
send()
Sends this email message using provided email sender.
|
void |
send(EmailSender emailSender)
Sends this email message using given email sender.
|
EmailMessage |
senderName(String senderName)
Sets explicitly the display name of the actual sender of this email message.
|
void |
setAttachments(List<EmailAttachment> attachments)
Sets attachments for this email message.
|
void |
setBccRecipients(List<EmailAddress> recipientsList)
Sets explicitly the list of email addresses who are BCC recipients of this email message.
|
void |
setBodyParts(List<EmailBodyPart> bodyParts)
Sets the list of parts that constituents the body of this email message.
|
void |
setBodyProperties(Map<String,Object> bodyProperties)
Sets the map with properties used for substitution of variables within the body of this email message.
|
void |
setCcRecipients(List<EmailAddress> recipientsList)
Sets explicitly the list of email addresses who are CC recipients of this email message.
|
void |
setCharset(String charset)
Sets explicitly the charset of this email message body.
|
void |
setFrom(EmailAddress from)
Sets explicitly the email address displayed in the field
From: of this email message. |
void |
setFrom(String fromAddress)
Sets explicitly the email address displayed in the field
From: of this email message. |
void |
setHeaders(Map<String,String> headers)
Sets given key-value map as header parameters of this email message.
|
void |
setRead(boolean read)
Sets read/unread flag for this email message.
|
void |
setRecipients(List<EmailAddress> recipientsList)
Sets explicitly the list of email addresses who are recipients of this email message.
|
void |
setReplyTo(List<EmailAddress> recipientsList)
Sets explicitly the list of email addresses who are supposed recipients of the replying on this email message.
|
void |
setSender(EmailAddress sender)
Sets the email address of the actual sender of this email message.
|
void |
setSender(String senderAddress)
Sets the email address of the actual sender of this email message.
|
void |
setSenderName(String senderName)
Sets explicitly the display name of the actual sender of this email message.
|
void |
setSubject(String subject)
Sets explicitly the subject of this email message.
|
EmailMessage |
subject(String subject)
Sets explicitly the subject of this email message.
|
EmailMessage |
text(String text)
Sets given text string as body of this email message.
|
String |
toJson(boolean isPrettyPrint)
Serializes this email message into JSON.
|
String |
toString()
Returns a string representation of this email message.
|
public static final String USED_DATE_TME_FORMAT_PATTERN
date field.protected String typeName
EmailMessage(String) or
EmailMessage(String, EmailSender)protected String id
protected Date date
protected String parentFolder
protected EmailAddress sender
protected String senderName
protected EmailAddress from
From: of this email message.protected List<EmailAddress> recipients
protected List<EmailAddress> ccRecipients
protected List<EmailAddress> bccRecipients
protected List<EmailAddress> replyTo
protected String subject
protected String charset
protected String text
protected String html
protected List<EmailBodyPart> bodyParts
protected Map<String,Object> bodyProperties
protected List<EmailAttachment> attachments
protected Boolean isRead
protected EmailMessage forwardedMessage
protected EmailMessage replyOnMessage
protected EmailSender emailSender
EmailSender that can be used for sending of this email message using method send()
and retrieving of parameters that are not specified explicitly.public EmailMessage()
The default type name: email.
It means if some parameters of this email message are not specified explicitly the email sender will try to
find them in configuration parameters of RPA platform under keys:
email.subject,
email.recipients,
email.cc.recipients etc.
public EmailMessage(String typeName)
The email type name defines where the email sender should find email message parameters if they are not
specified explicitly. The value of typeName defines keys of configuration parameters specified
within RPA platform and related to corresponding parameters of email message. Full keys of related configuration
parameters are formed as:
typeName.subject,
typeName.recipients,
typeName.cc.recipients etc.
It means if typeName is equal to "summary.email" keys of related configuration
parameters will be:
summary.email.subject,
summary.email.recipients,
summary.email.cc.recipients etc.
typeName - the name of email type.@Inject public EmailMessage(EmailSender emailSender)
This constructor is used in case of injecting of this EmailMessage using Inject annotation.
It's a convenient way that allows to avoid direct working with EmailSender:
@Inject
private EmailMessage message;
public void execute() {
...
message.subject(SUBJECT).text(BODY).send();
...
}
The default type name: email.
It means if some parameters of this email message are not specified explicitly the email sender will try to
find them in configuration parameters of RPA platform under keys:
email.subject,
email.recipients,
email.cc.recipients etc.
emailSender - the instance of EmailSender. It used for sending of this email message using
method send() and retrieving of email message parameters that are not
specified explicitly.public EmailMessage(String typeName, EmailSender emailSender)
This constructor should be used in case of extending EmailMessage by other subclasses. It allows implement
injecting of extended email class using Inject annotation and avoid direct working
with EmailSender:
@Inject
private SummaryEmailMessage summaryMessage;
public void execute() {
...
summaryMessage.setResults(someResults).send();
...
}
The typeName defines where the email sender should find email message parameters if they are not
specified explicitly. The value of typeName defines keys of configuration parameters specified
within RPA platform and related to corresponding parameters of email message. Full keys of related configuration
parameters are formed as:
typeName.subject,
typeName.recipients,
typeName.cc.recipients etc.
It means if typeName is equal to "summary.email" keys of related configuration
parameters will be:
summary.email.subject,
summary.email.recipients,
summary.email.cc.recipients etc.
typeName - the name of email type.emailSender - the instance of EmailSender. It used for sending of this email message using
method send() and retrieving of email message parameters that are not
specified explicitly.public String getId()
The value of unique identifier is present only for existing email messages of the mailbox.
null if this email message
is a new and have never been sent.EmailMessagingException - in case of some errors.public String getParentFolder()
The value of parent folder is present only for existing email messages of the mailbox.
null if this email message
is a new and have never been sent.EmailMessagingException - in case of some errors.public Date getDate()
This date represents received date if the email message has been received or sent date if the email message has been just sent.
Date object representing received or sent date of this email message.EmailMessagingException - in case of some errors.public ZonedDateTime getDateTime()
It provides the same date that is getDate() but as ZonedDateTime value.
ZonedDateTime object representing received or sent date of this email message.EmailMessagingException - in case of some errors.public Map<String,String> getHeaders()
public void setHeaders(Map<String,String> headers)
If some of given header parameters are already present in headers of this email message then they will be overwritten. Other headers of this email message that are not present in the given map will be left without changes.
headers - the key-value map with header parameters to set.public EmailMessage header(String key, String value)
key - the key string of the header parameter to set.value - the value string of the header parameter to set.public EmailAddress getSender()
The sender email address automatically is set by email service and corresponds to email account on behalf of
which this message is sent. Information about this email account is provided via EmailSender.getSecret().
EmailAddress object representing the email address of actual sender of this email message.public void setSender(String senderAddress)
This method is used by email service and shouldn't be used explicitly. The sender email address
automatically is set by email service and corresponds to email account on behalf of which this message is sent.
Information about this email account is provided via EmailSender.getSecret().
senderAddress - the email address string to set.public void setSender(EmailAddress sender)
This method is used for serialize/deserialize of this email message into JSON and shouldn't be used
explicitly. Since the sender email address string automatically is set by email server and corresponds
to email account on behalf of which this message is sent. Information about this email account is provided
via EmailSender.getSecret().
sender - the EmailAddress object with email address and its display name to set.public String getSenderName()
This display name is used ONLY if the value of from is not specified.
If the value of from is not set and the display name is not specified explicitly then it will be looked
up in configuration parameters of the RPA platform under the key that depends on the actual
typeName value:
<typeName>.sender.name
In case of default typeName the key of configuration parameter is email.sender.name.public void setSenderName(String senderName)
The actual sender is set by email service and corresponds to email account on behalf of
which this message is sent. Using this method it is possible to specify a display name that should be
displayed in the field From: instead of email address string but ONLY if the value of from
is not specified.
senderName - the string with display name of the sender to set.public EmailMessage senderName(String senderName)
The actual sender is set by email service and corresponds to email account on behalf of
which this message is sent. Using this method it is possible to specify a display name that should be
displayed in the field From: instead of email address string but ONLY if the value of from
is not specified.
senderName - the string with display name of the sender to set.public EmailAddress getFrom()
From: of this email message.
This value can be different from the actual email sender that is returned by getSender().
If this email address is not specified explicitly then it will be looked up in configuration parameters of
the RPA platform under the key that depends on the actual typeName value:
<typeName>.from
In case of default typeName the key of configuration parameter is email.from.
If this email address is not set at all then email address returned by getSender() will be displayed
in the field From: instead.
EmailAddress object representing email address displayed in the field From:
of this email message.public void setFrom(String fromAddress)
From: of this email message.fromAddress - the email address string to set.public void setFrom(EmailAddress from)
From: of this email message.from - the EmailAddress object with email address and its display name to set.public EmailMessage from(String fromAddress)
From: of this email message.fromAddress - the email address string to set.public List<EmailAddress> getRecipients()
This is a list of email addresses displayed in the field To: of this email message.
If recipients are not specified explicitly then they will be looked up in configuration parameters of
the RPA platform under the key that depends on the actual typeName value:
<typeName>.recipients
In case of default typeName the key of configuration parameter is email.recipients.
Email addresses in the value of this configuration parameter can be delimited with ";":
email.recipients = user1@example.com;user2@example.com;user3@example.com
EmailAddress objects representing email addresses who are recipients of this
email message.public void setRecipients(List<EmailAddress> recipientsList)
These are email addresses displayed in the field To: of this email message.
recipientsList - the list of EmailAddress objects representing email addresses to set as recipients
of this email message.public EmailMessage recipients(String... recipientsSequence)
These are email addresses displayed in the field To: of this email message.
recipientsSequence - the sequence of email address strings to set as recipients of this email message.public EmailMessage excludeFromRecipients(String... recipientsSequence)
recipientsSequence - the sequence of email address strings to exclude.public List<EmailAddress> getCcRecipients()
This is a list of email addresses displayed in the field CC: of this email message.
If CC recipients are not specified explicitly then they will be looked up in configuration parameters of
the RPA platform under the key that depends on the actual typeName value:
<typeName>.cc.recipients
In case of default typeName the key of configuration parameter is email.cc.recipients.
Email addresses in the value of this configuration parameter can be delimited with ";":
email.cc.recipients = user1@example.com;user2@example.com;user3@example.com
EmailAddress objects representing email addresses who are CC recipients of this
email message.public void setCcRecipients(List<EmailAddress> recipientsList)
These are email addresses displayed in the field CC: of this email message.
recipientsList - the list of EmailAddress objects representing email addresses to set as
CC recipients of this email message.public EmailMessage ccRecipients(String... recipientsSequence)
These are email addresses displayed in the field CC: of this email message.
recipientsSequence - the sequence of email address strings to set as CC recipients of this email message.public EmailMessage excludeFromCcRecipients(String... recipientsSequence)
recipientsSequence - the sequence of email address strings to exclude.public List<EmailAddress> getBccRecipients()
This is a list of email addresses displayed in the field BCC: of this email message.
If BCC recipients are not specified explicitly then they will be looked up in configuration parameters of
the RPA platform under the key that depends on the actual typeName value:
<typeName>.bcc.recipients
In case of default typeName the key of configuration parameter is email.bcc.recipients.
Email addresses in the value of this configuration parameter can be delimited with ";":
email.bcc.recipients = user1@example.com;user2@example.com;user3@example.com
EmailAddress objects representing email addresses who are BCC recipients of this
email message.public void setBccRecipients(List<EmailAddress> recipientsList)
These are email addresses displayed in the field BCC: of this email message.
recipientsList - the list of EmailAddress objects representing email addresses to set as
BCC recipients of this email message.public EmailMessage bccRecipients(String... recipientsSequence)
These are email addresses displayed in the field BCC: of this email message.
recipientsSequence - the sequence of email address strings to set as BCC recipients of this email message.public List<EmailAddress> getReplyTo()
If "replay to" recipients are not specified explicitly then they will be looked up in configuration parameters
of the RPA platform under the key that depends on the actual typeName value:
<typeName>.reply.to
In case of default typeName the key of configuration parameter is email.reply.to.
Email addresses in the value of this configuration parameter can be delimited with ";":
email.reply.to = user1@example.com;user2@example.com;user3@example.com
EmailAddress objects representing email addresses who are supposed recipients of
the replying on this email message.public void setReplyTo(List<EmailAddress> recipientsList)
recipientsList - the list of EmailAddress objects representing email addresses to set.public EmailMessage replyTo(String... recipientsSequence)
recipientsSequence - the sequence of email address strings to set.public String getSubject()
If subject is not specified explicitly then it will be looked up in configuration parameters of the RPA platform
under the key that depends on the actual typeName value:
<typeName>.subject
In case of default typeName the key of configuration parameter is email.subject.public void setSubject(String subject)
subject - string with subject to set.public EmailMessage subject(String subject)
subject - string with subject to set.public String getCharset()
If charset is not specified explicitly then it will be looked up in configuration parameters of the RPA platform
under the key that depends on the actual typeName value:
<typeName>.charset
In case of default typeName the key of configuration parameter is email.charset.public void setCharset(String charset)
charset - string with charset to set.public EmailMessage charset(String charset)
charset - string with charset to set.public List<EmailBodyPart> getBodyParts()
The email message body can be in a format of simple text or HTML. For compatibility it can be presented in
both formats at the same. To achieve it the body persisted as list of body parts where each part has
specific format. To get the full body in the text or HTML format methods getText() or getHtml()
should be used respectively.
If there are no body parts has been added explicitly this method will try to lookup the body content in
configuration parameters of the RPA platform under the key that depends on the actual typeName value:
<typeName>.body.tpl
In case of default typeName the key of configuration parameter is email.body.tpl.
Here can be actual text or HTML or it can be a path to Freemarker Template File (*.ftl) in the resources of current RPA process module. If such configuration parameter is present the content defined by this parameter will be added as HTML body part. In results the list with this single body part is returned.
EmailBodyPart objects representing body parts of this email message.public void setBodyParts(List<EmailBodyPart> bodyParts)
This method is used for serialize/deserialize of this email message into JSON and shouldn't be used
explicitly. To set a content of the body use following methods: text(String),
addText(String), html(String), addHtml(String).
bodyParts - the list of EmailBodyPart objects representing body parts to set.public EmailMessage text(String text)
It removes all existing text body parts and adds only one text body part with given text.
Instead of actual text string this method accepts path to FreeMarker Template File (*.ftl) in the resources of current RPA process module. In this case the content of the .ftl file will be used for adding of text body part.
text - the string with text to set or path to resource .ftl file with text to set.public EmailMessage addText(String text)
Instead of actual text string this method accepts path to Freemarker Template File (*.ftl) in the resources of current RPA process module. In this case the content of the .ftl file will be used for adding of text body part.
text - the string with text to add or path to resource .ftl file with text to add.public EmailMessage html(String html)
It removes all existing HTML body parts and adds only one HTML body part with given HTML.
Instead of actual HTML string this method accepts path to Freemarker Template File (*.ftl) in the resources of current RPA process module. In this case the content of the .ftl file will be used for adding of HTML body part.
html - the string with HTML to set or path to resource .ftl file with HTML to set.public EmailMessage addHtml(String html)
Instead of actual HTML string this method accepts path to Freemarker Template File (*.ftl) in the resources of current RPA process module. In this case the content of the .ftl file will be used for adding of HTML body part.
html - the string with HTML to add or path to resource .ftl file with HTML to add.public boolean hasHtml()
true if at least one of body parts is a html part or false otherwise.EmailBodyPart.isHtml()public boolean hasText()
true if at least one of body parts is a text part or false otherwise.EmailBodyPart.isText()public String getText()
This method takes all text body parts using getBodyParts() and joining them using "\n"
delimiter. If text parts are absent it gets html presentation of the body using getHtml() and
returns this html preliminarily converted into simple text format.
public String getHtml()
This method takes all HTML body parts using getBodyParts() and merges them into single HTML. If HTML
body parts are absent then instead of them text parts are taken.
public Map<String,Object> getBodyProperties()
The text or HTML content of the body part can be a FreeMarker template where some variables are used. These properties contains actual values of FreeMarker template variables. When the email message is ready to send the template is compiled and property values are substituted instead of variables based on their names that are correspond to property keys.
public void setBodyProperties(Map<String,Object> bodyProperties)
This method fully overwrites existing properties map.
bodyProperties - map with properties to set.public EmailMessage property(String key, Object value)
The text or HTML content of the body part can be a FreeMarker template where some variables are used. This method allows to specify values that should be substituted instead of these variables during template compilation.
key - the string that identifies a name of variable in the body template.value - the object that should be substituted instead of corresponding variable.public List<EmailAttachment> getAttachments()
EmailAttachment representing attachments attached to this email message.public void setAttachments(List<EmailAttachment> attachments)
attachments - the list of EmailAttachment representing attachments to set.public EmailMessage attach(File file) throws IOException
file - the File object representing file to attach.IOException - in case of errors during reading of given file.public EmailMessage attach(Path filePath) throws IOException
filePath - the Path to the file that need to be attached.IOException - in case of errors during reading of given file.public EmailMessage attach(String fileName, InputStream fileContent, String mimeType)
fileName - the string with file name that should be used for attached file.fileContent - the InputStream that provides the content of file to attach.mimeType - the string with content type of file to attach.public boolean hasAttachments()
true if this email message has attached files or false otherwise.public boolean isRead()
true is this email message is READ or false otherwise.public boolean isUnread()
true is this email message is UNREAD or false otherwise.public void setRead(boolean read)
The changing of this flag actually doesn't change anything in the mailbox. To apply these change in the mailbox
use the method EmailClient.updateMessage(EmailMessage).
read - the value of read/unread flag to set. It should be true if it's necessary to mark this
email message as read and false as unread.public EmailMessage markRead()
This method actually doesn't change anything in the mailbox. To apply these change in the mailbox use
the method EmailClient.updateMessage(EmailMessage).
public EmailMessage markUnread()
This method actually doesn't change anything in the mailbox. To apply these change in the mailbox use
the method EmailClient.updateMessage(EmailMessage).
public EmailMessage getForwardedMessage()
null if this message is not a
forwarding of some email message.public EmailMessage getReplyOnMessage()
null if this message is not a
replying on some email message.public EmailMessage forwardMessage(boolean withAttachments)
Before sending the generated email message should be set with list of recipients and additional content. Here is an example of using this method:
@Inject
private EmailSender emailSender;
public void execute() {
EmailMessage message = ...;
...
EmailMessage fwdMessage = message.forwardMessage(true)
.recipients("user@example.com")
.html("This email has been forwarded by robot.");
emailSender.send(fwdMessage);
...
}
withAttachments - whether files attached to this email message should be attached to the generated message.public EmailMessage replyMessage(boolean withAttachments)
Before sending the generated email message should be set with additional content and optionally with corrected
list of recipients. By default the list of recipients of the generated message includes only the email address
returned by getFrom() or by getSender() of this email message.
Here is an example of using this method:
@Inject
private EmailSender emailSender;
public void execute() {
EmailMessage message = ...;
...
emailSender.send(message.replyMessage(true).html("Robot replied to this email."));
...
}
withAttachments - whether files attached to this email message should be attached to the generated message.public EmailMessage replyAllMessage(boolean withAttachments)
Before sending the generated email message should be set with additional content and optionally with corrected list of recipients. By default the list of recipients of the generated message includes all TO and CC recipients of this email message excluding the current sender who is going to send the generated message.
Here is an example of using this method:
@Inject
private EmailSender emailSender;
public void execute() {
EmailMessage message = ...;
...
emailSender.send(message.replyAllMessage(true).html("Robot replied to all participants of this email."));
...
}
withAttachments - whether files attached to this email message should be attached to the generated message.public void send()
Does nothing if this email message has not been constructed using EmailMessage(EmailSender)
or EmailMessage(String, EmailSender). In such cases is necessary to use send(EmailSender)
instead.
EmailMessagingException - in case of some errors.public void send(EmailSender emailSender)
emailSender - the EmailSender that should be used to send this email message.EmailMessagingException - in case of some errors.public String toString()
public String toJson(boolean isPrettyPrint) throws com.fasterxml.jackson.core.JsonProcessingException
This method is recommended to use when it's necessary to transfer email message somewhere as text, e.g. between steps of the RPA process.
isPrettyPrint - whether the output JSON should have a pretty look or should be a one line string.com.fasterxml.jackson.core.JsonProcessingException - in case of some errors during JSON processing.public static EmailMessage fromJson(String json) throws com.fasterxml.jackson.core.JsonProcessingException
This method is recommended to use when it's necessary to restore email message after transferring from somewhere as text, e.g. between steps of the RPA process.
json - the JSON string that needs to deserialize into email message.com.fasterxml.jackson.core.JsonProcessingException - in case of some errors during JSON parsing.protected void beforeSend()
This method is intended to be overridden by subclasses if its necessary to specify values of variables used within FreeMarker template of the body. Also here can be done some other untypical actions like setting of charsets, subject etc.
protected String getConfigParam(String template)
typeName.template - the key template that depends on value of typeName.null if parameter is
not found or EmailSender is not provided for this email message.Copyright © 2023. All rights reserved.