Add custom header to outgoing messages

Below you’ll see how to add headers to an email with Postfix.

If you need to add 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 present? This cannot be done with bare metal Postfix.

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

The 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 option.

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.

To learn more visit MSH Traffic Policy website.

Łukasz is a software developer and owner of MSH Software company which builds email processing tools for Microsoft Exchange, Zimbra Collaboration Suite and Postfix. He specializes in server, desktop and web applications written in Java, .NET and C++.