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.

Starting with the following basic configuration to relay all messages in Postfix to PostMarkApp.com:

#start postmarkapps settings
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = static:secret:secret (where "secret is your API key")
smtp_sasl_security_options = noanonymous
relayhost = [smtp.postmarkapp.com]:25
#end postmarkapp settings

The problem with this is if for example something starts spitting out error messages they will all go through PostMark and cost money.

One way to bypass relayhost is to setup sender_dependent_relayhost_maps and have certain addresses map back to yourdomain.com. But this doesn't work in web apps where all messages are sent by the same user but with varying From headers.

So how can I achieve the same effect as sender_dependent_relayhost_maps but looking at the From or Subject headers instead of merely the user?

share|improve this question

2 Answers 2

You need Postfix 2.5 or later.

Then in main.cf set smtp_header_checks = pcre:/etc/postfix/dont_relay_this_header.

In /etc/postfix/dont_relay_this_header write

/^Subject:.*viagra/  REJECT You are not allowed to send out advertisement

Change the content of the dont_relay_this_header file as you need. More information is available in the header_checks manual.

share|improve this answer
    
This was one of the first things I tried by prepending a new To header on Subject match but it had weird effects. It worked if the recipient was in the same domain as $mydomain/$myhostname but it still went through relay_host (PostMark) for messages headed to other domains. Even when it did work it of course had display issues in Gmail due to the multiple To headers. –  Kyle MacFarlane Nov 19 '11 at 13:42
    
I meant to say by prepending a new From header in order to cause a match with sender_dependent_relayhost_maps. –  Kyle MacFarlane Nov 19 '11 at 13:52
1  
@KyleMacFarlane You SHALL not have two From: headers. –  mailq Nov 19 '11 at 23:02
up vote 0 down vote accepted

I solved this by attacking it from the other side, i.e. don't send mail going to a certain recipient through relayhost.

Edit /etc/postfix/main.cf:

#start postmarkapps settings
transport_maps = hash:/etc/postfix/transport
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = static:secret:secret (where "secret is your API key")
smtp_sasl_security_options = noanonymous
relayhost =
#end postmarkapp settings

Edit /etc/postfix/transport:

root@mydomain.com :
* smtp:[smtp.postmarkapp.com]:25

And run postmap /etc/postfix/transport.

Now I just send all my error messages to root@mydomain.com and they are not sent through PostMark.

share|improve this answer

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.