Inbound email action not working: when i send an email to that email address nothing happens

lando321
Tera Contributor

Hello everyone,

 

My intent was to create an inbound action that when an email is sent to the email address 'pg@cyberspace.com, that an incident will be generated, when i send an email to that email address nothing happens within the platform, but when i alter an already created email, i get some results, could someone advise on if i am using the correct filter?

 

Condition: email.to.indexOf('pg@cyberspace.com') >=-1

Actions

//	Note: current.opened_by is already set to the first UserID that matches the From: email address

current.caller_id = gs.getUserID();
current.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
current.assignment_group = '8a1fd3e51b7295105a78ca67624bcb9b';
current.short_description = email.subject;
current.category = 'Generic';
current.subcategory = 'Other';

//set CI
current.cmdb_ci.setDisplayValue('General - Service Unknown');

//current.category = "inquiry";
current.incident_state = IncidentState.NEW;
current.notify = 2;
current.contact_type = "email";

if (email.body.assign != undefined)
    current.assigned_to = email.body.assign;




current.impact = 3;
current.urgency = 3;

// if (email.importance != undefined) {
//     if (email.importance.toLowerCase() == "high") {
//         current.impact = 1;
//         current.urgency = 1;
//     }
// }

current.insert();
4 REPLIES 4

Tony Chatfield1
Kilo Patron

Hi, how is the message getting from pg@cyberspace.com to your instance?
If it is not forwarded correctly from the cyberspace.com mail server then your instance would not see the email as a new message and so an inbound action for 'New' would not be triggered.
Perhaps you can share xml of the received message and your inbound action so that they can be reviewed?

Hi @Tony Chatfield1 

What would be your recommendation to get the message to trigger? Below is the xml of the inbound action and the email:

<sysevent_in_email_action>
<action>record_action</action>
<active>true</active>
<assignment_operator/>
<condition_script>email.to.indexOf('pg@cyberspace.com') >=-1</condition_script>
<description>This inbound email action is triggered when an email is sent to ServiceNow and the email is not a reply or forward. This inbound email action can set the following fields on a new Incident: assigned_to priority In addition to being able to explicitly set the values of the above fields within the email, the following is done automatically: 1. The Incident caller_id is set to the the user who sent the email. 2. The email subject is set as the Incident short description. 3. The whole email is added to the Incident as a comment. 4. The Incident category is set to "inquiry". 5. The Incident state is set to "1". 6. The Incident notify is set to "2". 7. The Incident contact type is set to "email". Example email: This email will create a new Incident with the following: 1. The Incident caller is set to "Fred Luddy". 2. The Incident short description will be set to "Not able to connect to wireless network" 3. The whole email body is added to the Incident as a comment. 4. The Incident is assigned to "Bow Ruggeri" if the sender has the itil role. 5. The Incident category is set to "inquiry". 6. The Incident state is set to "1". 7. The Incident notify is set to "2". 8. The Incident contact type is set to "email". ----- From: Fred Luddy <fred.luddy@example.com> Subject: Not able to connect to wireless network Date: June 11, 2013 1:44:55 PM PDT To: ServiceNow The wireless network has been down for 30 minutes now. assign: Bow Ruggeri -----</description>
<event_name>email.read</event_name>
<filter_condition table="sys_email">
user!=spamadmin@cyberspace.com^NQsubject!=IronPort Spam Quarantine Notification^EQ
<item goto="false" or="false" field="user" endquery="false" value="spamadmin@cyberspace.com" operator="!=" newquery="false"/>
<item goto="false" or="false" field="subject" endquery="false" value="IronPort Spam Quarantine Notification" operator="!=" newquery="true"/>
<item goto="false" or="false" field="" endquery="true" value="" operator="=" newquery="false"/>
</filter_condition>
<from/>
<name>Create Incident (PG Cyber IT Support)</name>
<order>4</order>
<reply_email/>
<required_roles/>
<script>
<![CDATA[ // Note: current.opened_by is already set to the first UserID that matches the From: email address current.caller_id = gs.getUserID(); current.comments = "received from: " + email.origemail + "\n\n" + email.body_text; current.assignment_group = '8a1fd3e51b7295105a78ca67624bcb9b'; current.short_description = email.subject; current.category = 'Generic'; current.subcategory = 'Other'; //set CI current.cmdb_ci.setDisplayValue('General - Service Unknown'); //current.category = "inquiry"; current.incident_state = IncidentState.NEW; current.notify = 2; current.contact_type = "email"; if (email.body.assign != undefined) current.assigned_to = email.body.assign; current.impact = 3; current.urgency = 3; // if (email.importance != undefined) { // if (email.importance.toLowerCase() == "high") { // current.impact = 1; // current.urgency = 1; // } // } current.insert(); ]]>
</script>
<stop_processing>false</stop_processing>
<sys_class_name>sysevent_in_email_action</sys_class_name>
<sys_created_by>Phil.Knight@cyberspace.com</sys_created_by>
<sys_created_on>2022-10-27 16:38:17</sys_created_on>
<sys_domain>global</sys_domain>
<sys_domain_path>/</sys_domain_path>
<sys_id>b5db13e11bfe95106f8077761a4bcb65</sys_id>
<sys_mod_count>14</sys_mod_count>
<sys_name>Create Incident (PG Cyber IT Support)</sys_name>
<sys_overrides/>
<sys_package display_value="Global" source="global">global</sys_package>
<sys_policy/>
<sys_scope display_value="Global">global</sys_scope>
<sys_update_name>sysevent_in_email_action_b5db13e11bfe95106f8077761a4bcb65</sys_update_name>
<sys_updated_by>Phil.Knight@cyberspace.com</sys_updated_by>
<sys_updated_on>2022-12-06 20:47:37</sys_updated_on>
<table>incident</table>
<template>descriptionDYNAMIC367bf121ef3221002841f7f775c0fbe2^EQ</template>
<type>new</type>
</sysevent_in_email_action>
</xml>

 Email:

<sys_email>
<blind_copied/>
<body>test no real action needed</body>
<body_text/>
<checkpoint/>
<content_type/>
<copied/>
<deleted>false</deleted>
<direct/>
<error_string/>
<headers/>
<importance/>
<instance>a384922edb231510272ee58c13961927</instance>
<mailbox/>
<message_id/>
<notification_type>SMTP</notification_type>
<receive_type>new</receive_type>
<recipients>pg@cyberspace.com</recipients>
<reply_to/>
<state>processed</state>
<status/>
<subject>TEST EMAIL INBOUND</subject>
<sys_created_by>Phil.Knight@cyberspace.com</sys_created_by>
<sys_created_on>2022-12-06 20:45:53</sys_created_on>
<sys_id>3804de221b6fd1106f8077761a4bcbbe</sys_id>
<sys_mod_count>7</sys_mod_count>
<sys_updated_by>guest</sys_updated_by>
<sys_updated_on>2022-12-06 20:47:52</sys_updated_on>
<target_table>incident</target_table>
<type>received</type>
<uid/>
<user/>
<user_id/>
<weight>0</weight>
</sys_email>
</xml>

Hi, the script action, doesn't get recognized as valid xml if I try to paste into a container file and import into a PDI, so can't easily test end to end,

Looking at your email message the user and user ID fields are empty and I would expect that these would be populated with sys_id of the matched sys_user record, or if not matched the 'user' field would contain the email address of the sender.
Assuming the user was not matched is your instance configured to process email for unknown users?

and is your 'guest' account enabled?

Edit- your post answers this

<sys_updated_by>guest</sys_updated_by>

Not related, but email.to.indexOf('pg@cyberspace.com') >= -1 will always be true
as -1 means not found and anything greater than -1 is found, so >=  test results in both options returning true.

Hi @Tony Chatfield1 

I adjusted the condition to > -1, is there another way to test? Like i mentioned earlier, when i send the email to that address nothing happens, only when i alter an email record already in the instance.