How can I leverage certain fields from the email headers in a flow?
All versions of xMatters
If you look at what is logged in the Activity panel when you initiate a flow using the email trigger, you find there is a lot of items from the email header:
|email.to||The addresses the email was sent to (for example, WebUIAdmins@myinstance.xmatters.com).|
|email.senderIp||The IP address the email was sent from (for example, 184.108.40.206).|
|email.sender||The xMatters user configured to authenticate the email trigger (for example, mmcbride).|
|email.subject||The contents of the subject field (for example, Issue detected in web login service).|
|email.htmlBody||The body of the email in HTML markup.|
|email.plaintextBody||The body of the email in plain text.|
|email.headers.ARC-Authentication-Results||Email authentication results such as SPF, DKIM, and DMARC validation.|
|email.headers.ARC-Message-Signature||A DKIM-like signature of the entire message except for the ARC-Seal headers.|
|email.headers.ARC-Seal||A DKIM-like signature that includes the ARC Signature and the ARC Authentication Results header information.|
|email.headers.Accept-Language||The preferred languages set in the email client (for example, en-CA, fr-CA, en-US).|
|email.headers.Content-Language||The language the content is in (for example, en-US).|
|email.headers.Content-Type||The media type of the message content (for example, multipart/alternative).|
|email.headers.DKIM-Signature||DKIM signature containing information about the sender, the message, and the public key location required for verification.|
|email.headers.Date||Date and time the message was written (for example, Tue, 16 Jun 2020 18:02:58 +0000).|
|email.headers.From||The email address the message is from (for example, First Last <firstname.lastname@example.org>).|
|email.headers.MIME-Version||The MIME version of the email (for example, 1.0).|
|email.headers.Message-ID||A unique identified assigned to the message by the email client (for example, 7E4C8121-74D0-4473-8705-8B9BC4623C34@example.com).|
|email.headers.Received||A list of servers the email traveled through.|
|email.headers.Subject||The email subject (for example, Issue detected in web login service).|
|email.headers.Thread-Index||A values used by some email clients to support threading (for example, AQHWRAhe9PTa3R106EKT1QS6lt9jOw==).|
|email.headers.Thread-Topic||A values used by some email clients to support threading (for example, Issue detected in web login service).|
|email.headers.To||The address the email is sent to (for example, "email@example.com" <firstname.lastname@example.org>).|
|email.headers.X-<parameter>||Header parameters added by email clients for their systems and processes, such as spam detection.|
|email.headers.authentication-results||What the email client authenticated when the message was sent.|
|email.recipients||The xMatters target names of any recipients (for example, mmcbride)|
So, how do you access these items?
You need to create a custom step, and add a small amount of code. Here are the quick steps:
- First, define an input to bring in the email headers. In this example, we'll call the input 'email_headers'.
- Next, create an output. Let's say we want to have an output with the 'from' information.
- Use the script to map the information into outputs.
When mapping the header information to the output, use the input name plus the header parameter. For example, to map the email.headers.From parameter to an email_from output:
output['email_from'] = input['email_headers']['From'];
This pulls the information in the From parameter contained in the email_headers input. When you use the step in a flow, you'd populate the email_headers input with the email.headers output from the Email trigger.
You can also create a variable and use it when mapping parameters. For example:
var headers = input['email_headers']; output['email_from'] = input['email_headers']['From'];
You can use bracket or dot notation for single-word parameters:
['email_headers']['From'] can be entered as ['email_headers'].From
For full instructions on creating a custom step and defining inputs and outputs, see the online help.