Accessing email object variables
Summarize
Summary of Accessing email object variables
This guide explains how to access various pieces of an inbound email through object variables in ServiceNow. The global variablesysemailis available for use in inbound email actions, allowing for efficient email processing.
Show less
Key Features
- email.to: Contains a list of email addresses in the To: and Cc: fields.
- email.direct: Lists only the email addresses in the To: field.
- email.copied: Contains addresses in the Cc: field.
- email.bodytext: Provides the body of the email as plain text.
- email.bodyhtml: Gives the body of the email in HTML format.
- email.from: Contains the sender's email address based on matching with user records.
- email.subject: Contains the subject of the email as plain text.
- email.recipients: Lists recipient addresses as a plain text string.
- email.recipientsarray: Provides recipient addresses in an array format for scripting.
- email.importance: Indicates message importance (High, Low, or empty).
- email.headers: Contains details about the sender and routing information.
Key Outcomes
By utilizing these email object variables, ServiceNow customers can effectively process inbound emails based on various criteria, enabling automation and streamlined workflows. For instance, the recipientsarray can be used in scripts to handle each recipient individually, enhancing the system's responsiveness to email communications.
An inbound email action script contains the email object to access various pieces of an inbound email through variables. You can use the global variable sys_email with inbound email actions.
| Variable | Contents |
|---|---|
| email.to | Contains a comma-separated list of email addresses in the To: and Cc: boxes. |
| email.direct | Contains a comma-separated list of email addresses in the To: box. |
| email.copied | Contains a comma-separated list of email addresses in the Cc: box. |
| email.body_text | Contains the body of the email as a plain text string. |
| email.body_html | Contains the body of the email as an HTML string. |
| email.from | Contains an email address that depends on the following conditions:
|
| email.from_sys_id | Contains the Sys ID of the user who sent the email to the instance. |
| email.fromAddress |
If system property glide.email.inbound_action.extract_from_header property is set to true, origemail is computed from the headers. The default value is false if the property does not exist. |
| email.origemail | Contains the address of the email sender as listed in the email Headers field. |
| email.subject | Contains the subject of the email as a plain text string. |
| email.recipients | Contains a comma-separated list of recipient addresses as a plain text string, in the To: box. |
| email.recipients_array | Contains the recipient addresses as an array. |
| email.content_type | Contains the MIME content type of the email (for example,text/plain; charset="us-ascii" or text/html; charset="us-ascii"). |
| email.headers | Contains details about the sender, route, and receiver as a plain text string in the format of the sending email client. |
| email.importance | Contains an indication from the sender about how important a message is. The value can be High, Low, or empty. |
Inbound email.recipient variables
var rarray = email.recipients_array ; for ( var i = 0 ; i < rarray.length ; i ++ ) { var recipient = rarray [i ] ; // do something with it } The sys_email variable
This variable lets you access the received sys_email record that triggered the inbound email action. It can be used to reference fields on the email record, such as uid, sys_id, content_type, and so on.