Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking to configure postfix to route messages to different relays based on the contents of a subject line.

The desired result would be if a user sent an outbound e-mail with a specific tag say "SECURE:" at the start of the subject line it would forward to one relay ( but if the tag was not specified the message would be delivered another relay (

I have investigated header checks, before and after message filtering, and postfix proxy but I have not been able to pin down how to accomplish changing the mail route based on message contents (which seems like it should be a fairly simple thing to do).

I might expect to involve procmail for this task, but would like some assistance in where to begin. Can anyone assist?

share|improve this question

If I understand the manual correctly, you can achieve this using header checks with FILTER transport:destination.

From the header_checks part of the manual:

The transport name specifies the first field of a mail delivery agent definition
in; the syntax of the next-hop destination is described in the manual page
of the corresponding delivery agent.

In your case, this would be smtp:

So the full config:


header_checks = regexp:/etc/postfix/header_checks
relayhost =

In header_checks:

/^Subject: SECURE:/ FILTER smtp:

I haven't tested this at all.

share|improve this answer
I did a cursory test in my lab and this worked great. I did have to change the regex pattern to /^SECURE:/ FILTER smtp: Much better than my iptables suggestion. – InChargeOfIT Mar 2 '12 at 19:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.