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

Hello,

What is your solution?  I need to do the same.

Thanks,

Chad

Tudor
Tera Guru
Hi, Based on the logic that you described, you could potentially extract what comes after "@" - it a combination of indexOf and substring I believe - you can take a look at W3 https://www.w3schools.com/js/js_string_methods.asp. For the above, another option would be regex 🙂 But the issue is that some companies own several domain:. Com,.co.uk etc, ao you shouls extract only the domain - again strip away everything after "." Second issue: are you storing the domains that a partner company owns in a field on the core_company table? If so, you could perform a query on that field to see whether there are any occurences. For this keep in mind that a company can own several brands: google, youtube etc... Hope this helps, Tudor

LAXMI TODAKAR2
Tera Contributor

Hello mnreddy,

You can define sender's domain in email properties go to Inbound Email Configuration.

 You can mention all domains.

Hope this helps.

 

Thanks,

Laxmi

 

 

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]";
}