Introduction to Text Replacement
When processing each Action, Email2AT will first render the text in every input field using a special text replacement engine. The engine's syntax is similar to the syntax for mustache and handlebars templating engines, and you should be able to make quick sense of our text replacement engine if you are familiar with mustache or handlebars.
What Does it Do?
The text replacement engine renders text templates by interpolating supplied data into the template. The data includes the parts of an inbound email, as well as information returned from any previous actions taken during the processing of that email. The text template is what you have configured within our console when setting up your rules and actions.
For example, if you wanted to render the subject line of an email, you could use an expression like this:
{{email.subject}}
The power of a text replacement engine comes when you see how you can combine multiple pieces of information. Here's an example of a confirmation email you may want to have sent to your users after they open a new ticket:
Dear {{email.from.display}},
We have received your request titled {{email.subject}}, and we have created a new
ticket in our ticket management portal. If you have any further updates about your
issue, please contact our office and reference ticket number {{custom.TicketNumber}}.
Thank you,
IT Support Team
In this example, the email sent to the user would first have text replaced to include the user's actual name, the subject line of their email, and the ticket number we created from their email.
What Data is Available?
The text replacement engine can use text from the inbound email, as well as from previous actions. The very first action in a rule will contain only the default set of data from the inbound email. Any actions after the first action will also include any variables that were output from previous actions.
The default variables that are generated for every inbound email are:
variable name | description |
---|---|
email.subject | The subject line of the email |
email.mailbox | The email mailbox from which we retrieved the message |
email.messageid | The message ID header generated by the email sender's client |
email.from.address | The email address of the message sender |
email.from.display | The email display name of the message sender |
email.to.[0].address | The first email address the email was addressed to |
email.to.[0].display | The display name of the first email address the email was addressed to |
email.to.[n].address | The n'th email address the email was addressed to |
email.to.[n].display | The display name of the n'th email address the email was addressed to |
email.cc.[0].address | The first email address the email was CC'd to |
email.cc.[0].display | The display name of the first email address the email was CC'd to |
email.cc.[n].address | The n'th email address the email was CC'd to |
email.cc.[n].display | The display name of the n'th email address the email was CC'd to |
email.body | The body of the email. See details below. |
email.bodyparts.plaintext | The plaintext body of the email. |
email.bodyparts.html | The HTML body of the email (only if the email includes an HTML body). |
email.bodyparts.html_to_plaintext | The HTML body of the email with all HTML tags removed. |
email.body_stripped.visible | The part of email.body not including the sender's email signature or any quoted emails. If we don't find any signature or quoted text, this will include the entire body. |
email.body_stripped.signature | The email sender's signature block at the bottom of their email. |
email.body_stripped.quoted | The quoted copied of previously sent messages found at the bottom of the email. |
email.body
, email.bodyparts
, and email.body_stripped
?
What is the difference between Put succinctly, email.body
contains the full contents of the email message, email.bodyparts
contains the plaintext and html versions of the email, and email.body_stripped
breaks apart email.body
to separate out the email signature as well as quoted email replies.
When Email2AT parses an incoming email message, it first populates the following three variables:
email.bodyparts.plaintext
is populated with the plaintext version of an email if the email was sent multipart with a plaintext part, or it is populated with the entire body of the email if it was not sent multi-part. If the email was sent multipart and a plaintext version was not supplied, this variable will remain empty.email.bodyparts.html
is populated with the HTML version of an email if the email was sent multipart an HTML part. If no HTML version was supplied (or if the email was not sent multi-part), this variable will remain empty.email.bodyparts.html_to_plaintext
is populated with the contents ofemail.bodyparts.html
but with the HTML tags and code removed. Ifemail.bodyparts.html
is empty, this variable will remain empty, as well.
Once Email2AT has populated the 3 email.bodyparts
variables, Email2AT populates email.body
with the contents of email.bodyparts.plaintext
. If email.bodyparts.plaintext
is empty, but email.bodyparts.html_to_plaintext
has a value, then we populate email.body
with the contents of email.bodyparts.html_to_plaintext
.
In other words, email.body
will always contain the plaintext version of the inbound email, unless the email was sent with only an HTML version, in which case email.body
will be populated with the HTML version of the email but with the HTML tags removed. Generally speaking, email.body
is the first variable to consider when looking for the body of an email message.
Once email.body
is populated, Email2AT then attempts to split the email.body
text into 3 parts to store in email.body_stripped
:
- If Email2AT can identify a "quoted" portion of an email, it removes the quoted portion and places it in
email.body_stripped.quoted
. This section is often found in email replies and contains the contents of the message that is being replied to. - If Email2AT can identify a signature in the bottom of the email, it removes the signature and places it in
email.body_stripped.signature
. This section often includes the sender's name, address, phone number, etc. - If Email2AT identified a "quoted" or "signature" section, it places the remainder of the message in
email.body_stripped.visible
. This leaves just the body of the message with no signature and no copies of the previous message(s) quoted in the email. If Email2AT isn't able to identify any sections of the email that are "quoted" or "signature" sections, the entire email will be placed inemail.body_stripped.visible
. Because of this, it is safe to useemail.body_stripped.visible
, as it will either contain a cleaned up version of the email or the entire email, and will never remain blank.
In almost all cases, it is best to use either email.body
(which will include the email, signature, and replies), or email.body_stripped.visible
(which will include the portion of email.body
that remains after removing any email signature and quoted replies).
email.to.[0].address
and email.mailbox
?
What is the difference between The variable email.to.[0].address
contains the address the email sender typed in their email client to send you a message. The variable email.mailbox
contains the destination email mailbox that the email was ultimately delivered to.
For example, if a user sends an email to [email protected]
and if that address is configured to forward mail to [email protected]
, then email.to.[0].address
would contain [email protected]
, and email.mailbox
would contain [email protected]
.
In other words, email.to.[0].address
contains the public-facing email address (the address your sender knows about), and email.mailbox
contains the destination mailbox on our system.