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 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 action: runs a specified script.
- Reply 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 needed state, the system inserts the body of this email to the Additional comment 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 the presence of a certain text in the subject and the same task number as in the incident record.
To process inbound email, set up the default email account. See the Email Accounts article to learn how to do it.
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. One incoming email can trigger execution of none, one or several actions in a row, depending on the values of the Active, Order, 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:
- 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.
- 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.
- Depending on the value of the Action type field, a Script is executed, or a Reply email is sent.
- The value of the Stop processing when complete checkbox is checked
- If the checkbox is selected, the rest of the actions down the chain are skipped, and the processing chain is terminated.
- If the checkbox is not selected, the system proceeds to the next action and repeats Steps 1–4.
- 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:
Configure an inbound email action
- Navigate to System Notification → Inbound Email Actions.
- Click New and fill in the fields.
- Click Save or Save and exit to apply the changes.
Role required: admin.
Inbound Email Action form fields
Field | Mandatory | Description |
---|---|---|
Name | N | Specify an action name. |
Action type | N | Select the action type. Available options:
The Reply email action uses the default email account for sending emails, even when more than one email account is available. |
Message type | N | Specify a message type required to run the action. Available choice options:
|
DSN | N | Select this checkbox to trigger the action in response to Delivery Status Notification emails. |
Invitation | N | Select this checkbox to trigger the action in response to Invitation emails. |
Description | N | Add a detailed description of what this email action does. |
Reply email | N | Enter the text of the reply letter. It will be sent to the original email address that initiated the action. |
From | Y | Select a user, who initiates a script execution, or sends a response email. |
Script | N | Enter a script that triggered by the inbound email action. You can use all methods of server-side API classes. The following objects are available:
(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(); |
Active | N | Select this checkbox to activate the action. |
Order | N | Enter a number to define the order of action processing. Actions are processed in ascending order. |
Stop processing when complete | N | Select 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”, 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:
Field | Value |
---|---|
Name | Create incident (access issue) |
Action type | Record Action |
Message type | New |
Active | true |
Script |
Script example Expand source
(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 Log. You can filter these logs using the criteria below:
- Source IS Inbound Action
- Essence Document CONTAINS 0229fa8a-bcbe-1f11.
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 precise or imprecise condition operators.
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 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.
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'.
user.get('email', 'like', 'j.doe@mail.com')
The following example shows the script with the userIDbyEmail() method that searches for a user by email value:
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(); } }
- No labels