Routing based on the recipient's address


In the tutorial Routing based on the sender's address we have shown how you can route newly created tickets within todo4teams depending on the sender's address of an incoming email.

In the following example we will show how you can make a routing based on the the addressee of the email. This case is a little more complicated because an email may have several addressees - which may also just be mentioned in the CC- and BBC-part of the email's recipients.

An example how this will work: You offer your customer a variety of email addresses which provide a possibility of contact. Internally the incoming emails to these addresses are routed to a collective mailbox. In this case the whole subset of addresses is called alias addresses.

Now based on to the actual email addressees in the incoming mails to todo4teams the generated tickets are routed to a specified team.
This functionality can be mapped using the "Receive Action" within the configuration editor of the corresponding collective mailbox.
For this purpose it is necessary to implement a Javascript in the "Receive Action" of the mailbox.

In order to implement this Javascript an example.
There are the individual email addresses test@test.com (as the collective mailbox) and test1@test.com and test2.@test.com as the alias addresses.

addressbased_routing.png

Tickets to the address test1@test.com shall be processed to team 25, tickets for the address test2@test.com to team 26.

All other messages that do not include these recipients are routed to the team 27; this for example may be the mails that were addressed directly to the collective mailbox test@test.com.

Please adjust for your own purposes the email addresses and the affected teams.

If further adjustments are required, please feel free to contact us at support@bergener-bluma.de.

In the script, all the addressees are first summarized in a string  AllRecipients.

In the if/else construct is then checked whether the relevant addressee is contained therein and based on the result of this inquiry the matching ticket route is chosen.


var numRecipients = message.getAllRecipients().length;
var allRecipients = "";
for (var i = 0; i < numRecipients; i++) {
 var recipient = message.getAllRecipients()[i];
  allRecipients += recipient.toString()+", ";
}
 
if(allRecipients.indexOf('test1@test.com')>-1) {
   helper.routeToGroup(25);
} else if(allRecipients.indexOf('test2@test.com')>-1){
   helper.routeToGroup(26);
} else {
   helper.routeToGroup(27);
}