Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 (1.1.1.1) but if the tag was not specified the message would be delivered another relay (2.2.2.2).

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

1 Answer 1

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 master.cf; 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:1.1.1.1

So the full config:

In main.cf:

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

In header_checks:

/^Subject: SECURE:/ FILTER smtp:1.1.1.1

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:1.1.1.1. Much better than my iptables suggestion. –  InChargeOfIT Mar 2 '12 at 19:27

Your Answer

 
discard

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.