Accessing email object variables
Summarize
Summary of Accessing email object variables
In ServiceNow inbound email actions, thesysemailglobal variable provides access to the email object, enabling you to script responses and processing based on various components of an inbound email. This functionality is essential for automating workflows triggered by incoming emails.
Show less
Key Features
- Access to Email Fields: The
emailobject exposes key variables such asto,direct, andcopiedfor recipient addresses,bodytextandbodyhtmlfor the email content, andfromfor the sender’s address. - Sender Identification: The
email.fromvariable reflects the sender’s email address, matching an existing user if applicable, andemail.fromsysidprovides the user’s Sys ID in the system. - Additional Metadata: Variables like
subject,contenttype,headers, andimportanceallow scripts to read email subject, MIME type, raw headers, and priority respectively. - Recipient Arrays: The
email.recipientsarrayprovides an array of recipient addresses, facilitating iteration and conditional processing of emails based on recipients. - System Property Control: The
email.fromAddressvariable behavior can be controlled with the system propertyglide.email.inboundaction.extractfromheader, enabling extraction of sender address from headers if set to true. - RFC 2822 Compliance: Email addresses must comply with RFC 2822, using commas to separate multiple addresses, ensuring accurate parsing of recipient fields.
- Sysemail Record Access: The
sysemailvariable allows direct access to the inbound email record's fields likeuid,sysid, andcontenttype, enabling advanced scripting scenarios.
Practical Application
ServiceNow customers can use these variables in inbound email action scripts to:
- Extract and analyze sender and recipient email addresses for routing or automation.
- Process email content in plain text or HTML format for creating or updating records.
- Use email metadata like subject and importance to prioritize or categorize requests.
- Iterate over recipient arrays to apply logic based on multiple recipients.
- Reference the underlying sysemail record for detailed email attributes.
This enables efficient handling of inbound emails, improving automation, ticket creation, and workflow triggering based on email content and metadata.
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.