Inbound email actions allow defining actions an instance takes when receiving an email. They allow to process inbound email as either an automatic reply or as a record in the system. The processing takes the type of incoming mail and other attributes into account.
They are similar to business-rules in the usage of scripts and conditions that perform actions on the target table. Emails are checked by inbound email actions for defined conditions and some watermark that associates the email with a task. If the conditions are met, then the inbound email action performs the pre-configured activities. They may be of two types:
- Record Action: runs a specified script.
- Reply Email: when triggered, sends a reply email.
For inbound email processing, the default email account must be configured preliminary. Email processing to learn more about email accounts configuring. |
Inbound email actions are most commonly used to process emails (for example, create a new incident when a received incoming email contains "Incident" in the subject line).
Configuring 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 changes.
Field | Mandatory | Description |
---|
Name | N | Inbound action displayed name. | Action Type | N | The action type. Available options: - Reply Email
- Record Action.
When the Reply Email option is chosen, then the action behavior is to send an email in reply when triggered. When the Record Action option is chosen, then the script runs (it should be specified in the Script field). Please note that the Reply Email inbound action uses a default email account for sending emails, even when more than one email account is available. |
| Type | N | The message type required to run the action. Available choice options: - New – newly created letters, neither reply nor forward.
Reply – letters with distinctive features such as the subject line beginning with a recognized prefix (optionally) or Reply-To email header included in message.
Forward – forward letters, in line with the reply letters, usually can be distinguished by watermarks, or subject lines, or any other features.
- All – these category summarizes letters of all types (new and reply and forward letters).
| DSN | N | Select this checkbox to trigger the action in response to Delivery Status Notification letters. This option is applied as long as selected inbound action Type is All. |
| Invitation | N | Select this checkbox to trigger the action in response to Invitation letters. This option is applied as long as selected inbound action Type is All. |
| Description | N | Enter the detailed description of what this email action does (optionally). | Reply Email | N | Compose the email message. It will be sent to the source address which triggered the inbound action. | From | Y | Reference to the user, on behalf of which the script is executed, or the reply letter is sent. | Script | N | Enter a script that will trigger the inbound email action. You can use all methods of server-side API classes here. In the Inbound Action script, the email object is available. The object is the 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. For this, you need to use properties with names corresponding to the names of record fields. For example: 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(); |
|
| Table | N | Select the table where the action adds or updates records. | Active | N | Select this checkbox to activate the action. | Order | N | Enter the number to define the order of action processing. Actions are processed in ascending order (lower numbers are processed first). | Stop Processing | N | Select this checkbox to terminate other inbound actions after the current action runs. |
|
Use case
We need to configure an inbound action implementing the following logic:
We create an inbound action as below:
Field | Value |
---|
Name | Create incident (access issue) |
Action Type | Record Action |
Type | New |
Active | True |
Script |
(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 actions logging
Every inbound action triggering is logged in the Script Log table. These logs can be filtered using the criteria below:
The Essence Document field is responsible for email processed by inbound action. You can enter full address or a part of it, and you can use precision or imprecision condition operators, respectively. |
Use the Condition Builder to build filters that fit your needs.
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 in the Script column, you should 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 search a user by email value:
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();
}
} |