Text Replacement

When processing each Action, MSPintegrations 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 can include parts of an inbound email and information from previous actions. 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:

PropertyDescription
email.subjectThe subject line of the email
email.mailboxThe email mailbox from which we retrieved the message
email.messageidThe message ID header generated by the email sender's client
email.from.addressThe email address of the message sender
email.from.displayThe email display name of the message sender
email.to.[0].addressThe first email address the email was addressed to
email.to.[0].displayThe display name of the first email address the email was addressed to
email.to.[n].addressThe n'th email address the email was addressed to
email.to.[n].displayThe display name of the n'th email address the email was addressed to
email.cc.[0].addressThe first email address the email was CC'd to
email.cc.[0].displayThe display name of the first email address the email was CC'd to
email.cc.[n].addressThe n'th email address the email was CC'd to
email.cc.[n].displayThe display name of the n'th email address the email was CC'd to
email.bodyThe body of the email. See details below.
email.bodyparts.plaintextThe plaintext body of the email.
email.bodyparts.htmlThe HTML body of the email (only if the email includes an HTML body).
email.bodyparts.html_to_plaintextThe HTML body of the email with all HTML tags removed.
email.body_stripped.visibleThe 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.signatureThe email sender's signature block at the bottom of their email.
email.body_stripped.quotedThe quoted copied of previously sent messages found at the bottom of the email.

What is the difference between email.body, email.bodyparts, and email.body_stripped?

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 of email.bodyparts.html but with the HTML tags and code removed. If email.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 in email.body_stripped.visible. Because of this, it is safe to use email.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).

What is the difference between email.to.[0].address and email.mailbox?

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 first@mydomain.com and if that address is configured to forward mail to mydomain-inbound-support@email2at.com, then email.to.[0].address would contain first@mydomain.com, and email.mailbox would contain mydomain-inbound-support@email2at.com.

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.

Updated on May 23, 2024
Was this article helpful?

Related Articles

Need Support?
Can't find the answer you're looking for?
Contact Support