Create an inbound email action

You can create inbound email actions to define the actions that the system takes when an email is received.

Before you begin

Role required: admin

Procedure

  1. Navigate to System Policy > Email > Inbound Actions.
  2. Click New.
  3. Fill in the fields as described in the table.
    Inbound email actions
    Note: You might need to configure the form to see all fields.
    Table 1. Inbound Email Actions form fields
    Field Description
    When to run
    Name Enter a descriptive name for this email action.
    Target table Select the table where the action will add or update records.
    Action type Select the type of action the instance takes. Select Record Action to modify a record in the instance or select Reply Email to have the instance send an email back to the source of the inbound email.
    Active Select this check box to prevent the system from running additional inbound email actions after this one runs. Clear the check box to disable the action.
    Stop processing Select this option to stop processing after this inbound email action runs.
    Type Select the message type required to run the action. The action runs only if the inbound email is of the selected type. Available types are:
    • New: An email that is not recognized as a reply or forward.
    • Reply: An email with a watermark with an In-Reply-To email header, or whose subject line begins with a recognized reply prefix.
    • Forward: An email whose subject line begins with a recognized forward prefix, even if the email also contains a watermark or In-Reply-To header.
    Note: By default, inbound emails of the Forward type always generate new incidents regardless of the presence of a watermark. If this behavior does not match your business logic, you can change the recognized reply and forward prefixes to treat forwards like replies.
    Required roles Specify required roles the sender must have to trigger the inbound action.
    Order Enter a number that specifies when this inbound action runs relative to other inbound actions that use the same target table. The instance processes the action with the lowest order number first.
    From Select the user required to run the action. If a user is selected, the action runs only when the email sender matches the user name. Leave this field blank to perform the action for all users.
    Condition Specify the condition that must evaluate to true to trigger the inbound action. Build a condition with the choice lists or enter a statement that determines when the inbound email action runs. For example:
    email.subject. startsWith ( "chg:" )
    Actions
    Field actions Specify how information in the email is inserted into the record.

    For example, select [Created by] [From email] [Sender], so that when the request is inserted, you can see who it is for.

    This field appears if the action type is Record Action.
    Reply email Compose the email message to send to the source that triggered the inbound email action.
    Script Enter the script the action runs. Typically, this script uses the validators script include and email variables.

    A template is provided:

    (function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger) {
    
    	// Implement email action here
    
    })(current, event, email, logger);
    These are the objects available:
    • current: access the record referred to by the inbound email. For example, current.assigned_to accesses the person assigned to the task.
    • event: access one of the parameters of the originating event. For example, event.parm1 accesses the first parameter of the event or event.parm2 for the second parameter. See Events for more information.
    • email: access the inbound current email record. For example, email.subject accesses the content in the subject line of the email. See Email object variables for more information.
    • logger: add a message to the log file with the source set to email.<Sys ID of incoming email>. For example: logger.log ("Some information")
    Description
    Description Enter a detailed explanation of what this inbound email action does.
    Other fields
    Order Enter a number to define the order in which this email action should be processed. Actions with lower numbers are processed first. For more information. This field is not installed by the Ordered Email Processing plugin.

Email object variables

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.

Table 2. Accessing email objects with variables
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:
  • If the address listed in the email Headers field matches an existing user's Email address, this variable contains the user's email address.
  • If the address listed in the email Headers field does not match an existing user's Email address, this variable contains the address listed in the email Headers field.
email.from_sys_id Contains the Sys ID of the user who sent the email to the instance.
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.
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.
Note: The instance follows RFC 2822 (Internet Message Format), which requires multiple email addresses in a group to be separated by commas, not semicolons. The instance can set the values of the email.to, email.direct, and email.copied variables only if emails addressed to groups follow the expected RFC format.

Inbound email.recipient variables

The recipients variables (email.recipients, email.recipients-array) allow processing of inbound email based on the email recipients. For example, you can create a script to process email based on the array values:
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.