Tuesday, February 26, 2013

How to add custom header to outgoing messages

I'll demonstrate how to add headers to an email in Postfix. If you want to ONLY add custom header to all messages you might use ACCESS and PREPEND, see Postfix documentation for details.

But what if we assume that our custom header must be added only to outgoing messages and only if there is no one already? Unfortunately you cannot do this with bare metal MTA.

The best and easiest solution is to use MSH Traffic Policy milter.

Our first condition is to check if there is already a header in the message. Message Header condition will scan message for our X-Header. It have four options for matching headers - we need not have Header condition type.

Second conditions is to match only outgoing messages. If your domain is local.net then insert *@local.net value into Message Sender condition. This will filter only messages with internal sender.
The last element is to check if All conditions must met option is selected.

We have defined conditions, now it is time for actions. Add message header is what we looking for.
After these steps we have configured rule which will: Add custom header to all outgoing messages, but only when header does not exists.

Learn more about MSH Traffic Policy.

Tuesday, February 19, 2013

Run script when receive message

Ever wanted to execute command/script/application when receive certain email? Not for all messages but only from specific sender or message with some subject or maybe in specific time range? With MSH Traffic Policy it is easier than you think.
Run Executable action is one of many actions which can be invoked based on multiple conditions.
Run command only for certain messages
Executable path is an absolute path to the command which will be invoked. Arguments are optional. Wait for finish options means that when selected application will work synchronously and processing of the message will be stopped till command ends.
Wait for finish can be used in scenario where some application generate file and this file should be attached to the message.

Tuesday, February 12, 2013

Autoresponder loop protection

It happen when on other side of wire there is an auto reply software which has not have proper prevention functionality. This will create servers message war, because they will send infinite of emails.

Second case is when account receive a lots o spam, and many of this spam has bogus FROM address, so this account also receive many mailer-daemon responses while replying to that message.

MSH Autoresponder has built-in loop protection functionality.
Prevent of creating autoresponders loops between servers
MSH Autoresponder - Rule Wizard - Protection page
It simple. If you do not want to have protection then switch off Enable protection option (selected by default). Customization of auto reply density sending is also available - how many auto replies will be sent to the same recipient and in which time interval (ie. 15 minutes).

With this functionality you will not worry any more about loops.

Thursday, February 7, 2013

Block emails sending out to a particular domain

How to block sending and receiving emails from/to specific domain? Like:

  • AOL
  • Gmail
  • Hotmail
  • etc.

I will not use smtpd_sender_restrictions from Postfix, but create simple rule in MSH Traffic Policy.

1. The easiest way to do this is to create rule with block message action.
Block Message action.

2. Choose REJECT option.
Choose REJECT option from TYPE drop down menu.

3. Now go to Conditions tab and define domains which you want to block. For this example I'll use *@gmail.com. Select Message Sender condition from the list.
Message Sender condition.

4. Add domain gmail.com with asterisk character which will match any email address.
Sender email address.

5. Select Message Recipient conditions from the list.

Message Recipient condition.

6. Add domain gmail.com with asterisk and choose TO,CC and BCC option from drop down menu - with this none email will go through this filter.

In which fields search: TO, CC and BCC

7. Remember to select Any condition must met - with this option when only one condition is met message will be dropped.
Any condition must met to block message.

With that created rule no mail will go to or from gmail.com domain. There is no limit of defined domains, so adding new one is as easy as previous one.

Tuesday, February 5, 2013

Block attachments with Postfix

With MSH Attach Filter (freeware) milter application you can block or remove any attachment you want.

You can also:
  • filter by attachment name, content type, size
  • add, remove and compress attachments
  • block message with suspicious files

Block message with certain attachments

First way is to block email containing specified attachments.

You need to define blocking action:

<block-message type="discard"/>

And one condition which will execute block message action. In this example it will block attachments with extensions: bat, com, exe, dll and vbs.

<attach-name value="*.bat;*.com;*.exe;*.dll;*.vbs">

Remove attachments from message

Another solution is to only remove attachments from message without block email.

It is even simpler because you need only define one action. This time it will remove attachments greater than 1 MB:

<attach-remove-size value="1" unit="mb" cmp="gt"/>

This was a simplest configuration when you need to dump attachment from messages.

Saturday, February 2, 2013

Change subject for specified email recipient - Postfix/Sendmail

There is many ways to modify the message subject in Postfix and Sendmail based on message recipient, but the simplest way is to use milter MSH Traffic Policy. This software can do a lot of more than change and rewrite subject, you can: take care of attachments, block spam, manage MIME headers and many more.

So lets see how to create simple rule to modify message subject.

1. Add new rule by clicking Add Rule button.

2. When rule wizard will open, on Actions tab click Add button and choose from menu Modify Message Subject position.

3. Define new subject for the message. To insert old message use $SUBJECT variable.

4. If we want to rewrite subject only for one user then on Conditions tab click Add button and choose Message Recipient position.

5.Enter recipient email address (like john.doe@host.local) and choose in which field to search for this recipient. We want to change message subject when our defined recipient is in TO or CC field. So choose from combo box "in TO and CC field" position.
6. On Name tab define name for new rule, ie. Rewrite subject for user john.doe@sendmail.local and then click OK button.

7. When you create new rule click Save All button and you are ready to test your configuration.

To learn more visit MSH Traffic Policy website.