But what if I don’t want <i>all</i> my mail relayed?
Amazon’s EC2 address space is dynamic, which means it is a perfect haven for spammers and others persons of ill repute to hang out. Unfortunately that means that a lot of the email providers don’t trust email coming out of there as not-spam. The solution is to use a 3rd party smtp server, either directly or as a relay. The most common configuation involving relaying and EC2 seems to be Paul Dowman’s A rock-solid setup for sending SMTP mail from your EC2 web server. This setup, while effective, has a pretty nasty drawback that he outlines at the bottom. And that is all your mail is sent as the account you are relaying through.
But what if you don’t want all your mail sent at that user? Well, in general, it appears that you are out of luck, except in one specific use case. Fortunately for me, I am that use case.
Our application sends email to two broad categories of recipient: users (password resets, invite others, etc.) and us (feedback). Or said another way, mail we want relayed and mail we don’t. Relaying would still work technically in both cases, but what we really want is to have the feedback to come ‘from’ the user’s email so we can respond to it. (We also have FogBugz wired up to auto-respond to some accounts which is even more killer a feature than the project prediction)
Luckily, postfix has the ability to be configured this way. Here are the deviations / additions from Paul’s instructions.
- Remove the global relayhost from main.cf
#relayhost = [mail.authsmtp.com] relayhost =
- Specify a transport_map in main.cf
transport_maps = hash:/etc/postfix/transport
- Now create the transport map ```
yourcompany.net :
- smtp:[relay.othercompany.com] ```
What this says is that any mail going to yourcompany.net is not relayed (so retains the From information) and everything else gets pumped through relay.othercompany.com’s smtp server
- Convert the file to something postfix knows how to read
postmap /etc/postfix/transport
- It is likely also a good idea to fix the permissions of the file too.
chown root.postfix transport* chmod 0640 transport*
- reload the configs into postfix with
postfix reload
- And then test your config to make sure you didn’t completely screw it up.
This still doesn’t solve the issue of being able to dynamically decide when to relay through different accounts, but it does solve the integration with FogBugz problem. Now, does any postfix wizard out there know how to determine the relay, not on the recipient’s address but the sender’s?