How to identify the sender's email domain and add it to work notes using email inbound action

mnreddy
Mega Guru

We are using "Create Incident" email inbound action to create incidents from emails that will be sent out to our instance. Emails will be received from all domains (Gmail, yahoo, outlook etc.). The requirement is to read the email sender's domain and add a work notes based on his/her domain so that support group will know if it came from a known domain or not. Known domains are all the partners that are working with the company (The list is almost over 200).

I am aware that I can use if(email.from.toString().toLowerCase().indexOf('gmail.com')>=0) to read the email domain from the sender email address. Since the known domain list is over 200, how can I compare it with the known domain list what I have to see if the email came from a known domain or not? Any thoughts? Thanks in advance.

1 ACCEPTED SOLUTION

mnreddy
Mega Guru

I achieved it through below code:

var kDomains = ["abc.com", "xyz.com"];
var kDomains1 = kDomains.toString().split(',');
var count = 1;
for (var x = 0; x < kDomains1.length; x++) {
count++;
if (email.from.toString().toLowerCase().indexOf(kDomains1[x]) >= 0) {
current.work_notes = "[code]<p> <h3 style='color:purple; font size=5;'>" + 'Email from a Known domain'+ "</h3></p>[/code]";
break;
}

}
if (count > kDomains1.length && email.from.toString().toLowerCase().indexOf('<your organization domain') == -1) {
current.work_notes = "[code]<p> <h3 style='color:red; font size=5;'>" + 'Email from unknown domain' + "</h3></p>[/code]";
}

View solution in original post

8 REPLIES 8

P-Rudenko-SN
ServiceNow Employee
ServiceNow Employee

Hello, I'd create a system property (table 'sys_properties') to put there the domain list.

Then use gs.getProperty('your_property_name') in your script.

Hope this helps.

Hello @Pavlo Rudenko ,

Thanks for your response. My question is how can I extract the domain from the sender's email and how can I compare it with the values in system property to see if the domain is listed as a known domain in the system property values or not? Thank you.

P-Rudenko-SN
ServiceNow Employee
ServiceNow Employee

@mnreddy You can try something like this:

var domain = mail_from.substring(mail_from.indexof("@")); //get the values from the email sender, that goes after @
var d_prop = gs.getProperty('your_property_name'); //list of trusted domains
if(d_prop.includes(domain)){
//check if the senders domain is in list
//do what is required 
 
}

@mnreddy did you check my reply? Please mark it as helpful and correct if it fits your needs.