Redirect emails based on message subject - check two headers at time

Below you will find a description of how to redirect a message based on sender and subject. We will use MSH Traffic Policy milter application which integrate with Postfix and Zimbra.

After installing server and desktop module we can start to create a rule which will do what we need.

Create a Rule

Start the application and connect to the mail server. Select Rules node and click Add Group button. We need to add rules group which will contain our new rule. Name it like Redirect Rules. Select our new Redirect Rules node and on the right panel click Add Rule button. Rule wizard will open.

With wizard we will define actions, conditions, exceptions and rule name. With Actions we will redirect our message, conditions and exceptions will help us to match messages which should be redirected.

Define Conditions

We will begin with conditions. In our scenario, we want to redirect messages that are sent from the @xcompany.com domain and include the INVOICE phrase in the message subject. The word “and” is important here, because messages which don’t have INVOICE text in subject or are not from specified domain should go through without change.

Switch to Conditions tab, click Add button and choose Message Sender – Email Address menu. Select Wildcards from drop down menu option and put *@xcompany.com text in Email addresses text input. Click OK button.

Sender condition added, now is time for the message subject. Click Add button and this time choose Message Subject or Body contains menu. Select Subject option in Search from drop down menu. Choose Wildcards in Match text with option. Put *INVOICE* text in Word or Phrase text input. Click OK button.

At the bottom of the rule wizard, on the Conditions tab, select the All conditions met option.

Choose an Action

Go back to the Actions page. Now we will define the action to be taken on messages that meet our conditions.

To forward a message, we need to apply two actions: Add Envelope Recipient and Add Message Header. This is because the envelope recipient will only modify the recipients address list without adding a MIME message header. The recipient will receive the message but will not see their own email address in the TO/CC/BCC fields.

Click Add button and choose Add Envelope Recipient menu. Provide an email address which should receive a copy of the message. For this scenario we will use john.doe@soft.com example address. Now click Add button and choose Add Message Header menu. Put CC text as Header Name and john.doe@soft.com in Header Value field. Click OK button.

We had defined condition criteria to match messages and actions which should be taken. Switch to Name tab, give a rule name, like Redirect Messages from @xcompany.com with INVOICE in subject. Click OK button to close rule wizard.

Save and Verify

To apply changes click Save All button.

Now when messages with the specified phrase in the subject and sent from the @xcompany.com domain go through the mail server, they will automatically also be sent to john.doe@soft.com. The original recipient of the message will also receive it.

To learn more visit MSH Traffic Policy website.