Routing based on the sender's address
This tutorial will show how to route incoming emails by their sender's email address. This is useful e.g. if you have a common support address "support@myservice.com" and want to distribute incoming emails to different teams.
In the following example we will route emails from all senders "*@somecompany.com" to the group with id 25 and emails sent from "*@anothercompany.com" to group 26.
Please start todo4teams and log in with the role "admin" or "superadmin" - depending on your user rights. As an administrator you need to have the rights to configure email boxes in todo4teams.
Select the tab "Email" and click on the table row of the email address you want to configure. Click on "Edit" to open the configuration dialogue.
Now select the tab "receive action" to edit the receive script. Copy the following script into the upper text pane:
if(senderAddress.indexOf('@somecompany.com')>-1){
helper.routeToGroup(25);
} else if (senderAddress.indexOf('@anothercompany.com')>-1){
helper.routeToGroup(26);
}
Change the domain names and group ids according to your installation and needs. Click "Save" and try the routing by sending messages from the different sender domains to his email box.
It's always a good idea to check the sender's address with the indexOf method because the sender might be written as "john.doe@somecompany.com" or something like "Doe, John <john.doe@somecompany.com>". indexOf() works in both cases.
Please note: Emails from all other addresses will be routed according to the setting in "address to" in the email box's "basic data" tab. Always set a correct default routing there!
We used the method helper.routeToGroup() and set the group's id as the parameter. There also is a method helper.routeToGroupByName() which takes the group's name as the parameters. You shoud prefer the first method because it makes your script robust against renaming the group and typos.