Best way to have an Inbound Email Action for specific addresses and multiple recipients

Kristian Maiora
Tera Contributor

We have Inbound Email Actions for (among other things) creating Cases in our HRSD environment. We have one rule that runs when:

Recipient contains hr@testorg.com

And it creates an HRC for the general HR assignment group. We have another rule that runs when:

Recipient contains payroll@testorg.com

And it creates an HRC in the Payroll assignment group.

Today we received an email to payroll@testorg.com with individuals also on the recipient list, however no other group email. The rule that ran was for the HR assignment group case. Looking at it more, one of the usernames on the payroll@testorg.com email is blihr, so their email is blihr@testorg.com. Technically that contains hr@testorg.com, which is why it triggered the HR assignment group rule and not the Payroll one.

 

I'm sure I could change the order the rules run and have the Payroll one before the HR one, but is there a better way to solve for this? I know that using Recipient is hr@testorg.com wouldn't run if additional addresses are on the email list, so I would love to hear some thoughts, feedback, and maybe a solution.

 

Thanks,

Kristian

9 REPLIES 9

johnfeist
Mega Sage
Mega Sage

Hi Kristian,

 

Among the attributes you have in the inbound email action are email.to and email.recipients_array.  The difference is that the array has already done a split of the multiple recipients.  I'd suggest that you iterate through the array looking for equality and not contents.  What you cannot control is what to do if two or more of your triggering email addresses are on the same email.

 

You can create a property that will let you know what recipients you need to find.  What I've done to avoid long strings of if, then else, is to store the property in the format sender~assignment group.  That way all you need to do is fetch the property and split it based on the delimiter between the mailboxes.  From there you can iterate through the array of mailboxes, splitting each cell into two so that when you find a match you already know the assignment group.

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

Thanks for the suggestion, @johnfeist . I'm fairly new to this space, so to be clear, you would suggestion creating a System Property that contains hr@testorg.com and payroll@testorg.com, possibly among other emails as needed. Then in the Inbound Email Action you would edit the script the iterate through the emails and it would take an action on which email it finds, understanding if multiple triggering emails are in the Recipient field it wouldn't work.

 

I just wanted to make sure I understand the general concept before I start trying to work on something.

 

Thanks again.

Hi Kristian,

 

You are correct.  I take it one step farther.  If the property looks something like this:

hr@testorg.com~Assignment Group1;payroll@testorg.com~Assignment Group2;...

When you start looking for a mailbox, you pull in the property (gs.getProperty()) and then as you iterate through them, split each one into two cells:

var theProperty = gs.getProperty("myEmailsProperty);
var thePropertyArray = theProperty.split(";");
var keepGoing = true;
for (var i = 0; i < thePropertyArray.length && keepGoing == true; i++) {
   var thePropertyCells = thePropertyArray[i].split(~);
   if (email.to.toLowerCase().indexOf(thePropertyCells(0).toLowerCase()) >=0 {
   <assign the ticket based on thePropertyCells[1]>
   keepGoing = false;
}

The nice thing about the above is that if you need to change senders and/or assignment groups you just do it in the property and don't have to change code.  I always do text comparisons setting both sides to either upper or lower case to avoid missing a match because of case differences between the two components.

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

Fantastic. I'll run this by the rest of the team and see what they think, but I appreciate the help and knowing that there is something that could be done here.