Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Inbound email actions are most commonly used to process emails. For example, if an incoming email contains “Incident” in the subject line, the system creates an incident record.

Inbound email actions are similar to business rules in the usage of scripts and conditions that perform actions on the target table. Inbound email actions verify emails for defined conditions and marks features that associate an email with a task. If the conditions are met, the inbound email action performs the pre-configured activities. There are two types of them:

  • Record Actionaction: runs a specified script.
  • Reply Email: when triggered, sends email: sends a reply email.

Unlike Notification Rules, inbound email actions enable the user to interact with the records in the system.

For example, while processing an incident in the Information Neededneeded state, the system inserts the body of this email to the Additional Commentcomment field in the Activity Feed when the caller sends their response. To do so, an inbound email action is created. The condition for this action is that the caller's email contains a specific the presence of a certain text in its the subject , and the same task number it includes matches the one as in the incident record. That is, the inbound email action defines what happens in the system after receiving an email.

Image RemovedImage Added

Note

To process inbound email, set up the default email account. See the Email Accounts article to learn how to configure the default email accountdo it.

Inbound action chain

Inbound actions include three major groups of parameters:

An action to execute when an email is received. It is defined with a script.

Email processing chain


The order in which an incoming email is processed is determined by the following parameters:

  • A condition that an email should meet for the action to be executed.
  • An action type to execute when an email is received.
  • Parameters that control the processing flow.

The third group of parameters is required to organize multiple inbound email actions in a way that they check an incoming email to match the condition defined in each of them, in a certain order. The less is the value in the Order field of an inbound action, the earlier this inbound action checks if a received email matches its execution condition. As a result, each email goes through an ordered chain of condition checks, from the inbound action with the least Order value to the one with the biggest, with the following processing logic: One incoming email can trigger execution of none, one or several actions in a row, depending on the values of the ActiveOrder, and Stop processing when complete fields of the action.

The inbound email actions are processed starting from the action with the lowest Order, according to the following logic:

  1. If the inbound email action is active (the Active checkbox is selected), the system starts checking the incoming email according to the action conditions.
    • If the action is not active, the system moves to the next one in Order.
  2. The email is checked against the conditions of the action.
    • If the email does not match the conditions, the system skips the action and proceeds to check the next action from Step 1.
  3. Depending on the value of the Action type field, a Script is executed, or a Reply email is sent.
  4. The
  5. If the Active checkbox is disabled (its value is set tofalse), this inbound action is skipped. The inbound actions with the Active checkbox enabled (its value is set totrue)are processed further.
  6. If an email matches no condition of any inbound action, it passes all the way down the processing chain, and no action will be executed.
  7. If the condition of an inbound action is matched, the execution of the action script of that inbound action starts. The further processing flow depends on the value of the Stop processing when complete checkbox of this inbound action:is checked
    • If the checkbox is
not
    • selected, the
email is checked to match the condition
    • rest of the
next Inbound Action
    • actions down the chain are skipped, and the
logic proceeds from Step 2 again
    • processing chain is terminated.
    • If the checkbox is not selected, the
rest of the inbound actions down the chain are skipped, and the processing chain is terminated. 
    • system proceeds to the next action and repeats Steps 1–4.
  1. The email processing ends when the system completes all active actions or when an action is performed with the Stop processing when complete checkbox selected.

The email processing chain is shown in the diagram below:

Image Added

As a result, one inbound email can trigger execution of none, one or several action scripts in a row, depending on the values of the Active, Order and Stop processing when complete fields in each inbound action defined in the system.

Image Removed

Configure an inbound email action

  1. Navigate to System Notification → Inbound Email Actions.
  2. Click New and fill in the fields.
  3. Click Save or Save and Exitexit to apply the changes.
Tip

Role required: admin.

Inbound Email Action form fields

FieldMandatoryDescription
NameNSpecify an action name.
Action
Type
typeN

Select the action type. Available options:

  • Record
Action
  • Reply Email
  • When the Reply Email option is selected, the action sends an email in reply when triggered.

    • action – when triggered, the Script runs.
    • Reply email – when triggered, an email is sent to the address that initiated the action. Its content is determined by the Reply email
    When the Record Action option is selected, the script runs. It should be specified in the Script
    • field.
    Note

    The Reply

    Email inbound

    email action uses

    the default email account for sending emails, even when more than one email account is available.


    Message typeN

    Specify a message type required to run the action. Available choice options:

    • New – newly created emails, neither reply nor forward.
    • Reply – emails with

    distinctive features such as
    • a subject

    line starting with a recognizable prefix (optional) or a Reply-To email header included in the message.
    InfoThe message type is defined by the content of the email subject. Keywords for reply emails are defined
    , in line with the reply emails, usually can be distinguished by watermarks, subject lines, or any other features. InfoThe message type is defined by the content of the email subject. Keywords for forwarding emails are
    DSNN

    Select this checkbox to trigger the action in response to Delivery Status Notification emails

    . NoteThis option is applied to inbound actions with Message Type set to All

    .

    InvitationN

    Select this checkbox to trigger the action in response to Invitation emails

    . NoteThis option is applied to inbound actions with Message Type set to All

    .

    DescriptionN
    Enter
    Add a detailed description of what this email action does.
    Reply
    Email
    emailN
    Compose an email message

    Enter the text of the reply letter. It

    is

    will be sent to the

    source

    original email address that

    caused

    initiated the

    inbound

    action.

    FromY
    Refer to

    Select a user, who initiates a script execution, or sends a response email.

    ScriptN

    Enter a script that

    triggers the

    triggered by the inbound email action. You can use all methods of server-side API classes

    here

    .

    Info
    In the inbound action script, the

    The following objects are available:

    • email
     is the
    • is an instance of the SimpleRecord class and refers to a record from the Email (sys_email) table that the action will process. To get the values of the record fields, use the dot-notation for the email object. To do so, use properties with names corresponding to the names of record fields.
    • event is an instance of an entry in the Inbound Email Actions (sys_email_inbound_action) table. 
    Code Block
    languagejs
    themeEclipse
    linenumberstrue
    (function runAction(/*SimpleRecord*/ event, /*SimpleRecord*/ email) {
    const newTask = new SimpleRecord('task');
    newTask.subject = email.subject;
    newTask.description = email.body_text;
    if (email.blind_carbon_copy) {
        newTask.attention_required = true;
    }
    cosnt insertedTaskID = newTask.insert();



    ActiveN

    Select this checkbox to activate the action.

    OrderNEnter a number to define the order of action processing. Actions are processed in ascending order
    (lower numbers are processed first)
    .

    Stop processing when complete

    N

    Select

    this checkbox to terminate other inbound actions after the current action runs

    the checkbox to end the message processing after the current action is completed. All subsequent actions (with a higher Order) are ignored.

    Use case


    You need to configure an inbound email action implementing the following logic:

    • When the system receives an email with the subject containing the keyword “access”access, a new incident is created and assigned to the group responsible for security and access to the system and data.

    Create an inbound email action as shown below:

    FieldValue
    NameCreate incident (access issue)
    Action
    Type
    typeRecord Action
    Message
    Type
    typeNew
    Activetrue
    Script


    Code Block
    languagejava
    themeEclipse
    titleScript example
    linenumberstrue
    collapsetrue
    (function runAction( /*SimpleRecord*/ event, /*SimpleRecord*/ email) {
    
        ss.importIncludeScript('EmailHelper');
        const helper = new EmailHelper();
    
        const letter = email.subject.match('aсcess'); // Keywords checking
        if (letter) {
            const incident = new SimpleRecord('itsm_incident');
            incident.subject = email.subject;
            /* If the sender's address is registered in the system,
            the Caller field will contain reference to an existing User record.
            If the address is unknown, the caller will be defined as Guest */
            incident.caller = helper.userIDbyEmail(helper.parseSender(email.from));
    
            incident.description = email.body_text;
            incident.state = '-2'; // Registered
            incident.contact_type = '20'; // Email
            incident.assignment_group = '162920380313692887'; // Security Group
            incident.impact = '2'; // Moderate
            incident.urgency = '2'; // Moderate
            const insertedIncidentId = incident.insert();
    
            if (insertedIncidentId != 0) {
                ss.debug(`Email ${email.sys_id} processing result: Incident with ID ${insertedIncidentId}`);
    
                const attach = new SimpleAttachment();
                attach.copy('sys_email', email.sys_id, 'itsm_incident', insertedIncidentId);
                return;
            }
            ss.error(`Inbound Action Failed!\nErrors:` + JSON.stringify(incident.getErrors(), null, 2));
        }
    })(event, email);


    Inbound email action logging

    Every inbound email action triggering is logged in the Script Logtable. You can filter these logs using the criteria below:

    • Source IS Inbound Action
    • Essence Document CONTAINS 0229fa8a-bcbe-1f11.
    to build filters that suit your needs
    Note

    The Essence Document field is responsible for email processed by the inbound email action. Enter the full address or a part of it, and use precision precise or imprecisionimprecise condition operators.

    Use the condition builder 

    .

    Recommendations

    The incoming mail parsing returns the address value for the From field of a record from the Email (sys_email) table in lower case. 

    When searching for a user by the email by email in the Script column, do not use the IS operator because the value of email can be entered with uppercase letters. For example, J.Doe@mail.com.

    Code Block
    languagejs
    themeConfluence
    titleNot Recommended
    user.get('email', 'j.doe@mail.com');

    Also, do not use the LIKE operator when searching for a user by email because the search will find a user with a similar email, for example, 'raj.doe@mail.com'.

    Code Block
    languagejs
    themeConfluence
    titleNot Recommended
    user.get('email', 'like', 'j.doe@mail.com')

    The following example shows the script with the userIDbyEmail() method that search searches for a user by email value:

    Code Block
    languagejs
    themeEclipse
    linenumberstrue
    ss.importIncludeScript('EmailHelper');
    class MyEmailHelper extends EmailHelper {
        userIDbyEmail(email) {
            const user = new SimpleRecord('user');
            user.addQuery('email', 'startswith', email);
            user.addQuery('email', 'endswith', email);
            user.selectAttributes('sys_id');
            user.setLimit(1);
            user.query();
            if (user.next()) {
                return user.sys_id;
            }
            return this.searchGuest();
        }
    }


    Table of Contents
    absoluteUrltrue
    classfixedPosition

    /

    Panel
  • Inbound Email Properties
  • Email Properties
  • Outbound Email Properties