How to Redirect All Outgoing Email from Postfix to a Single Address for Testing

emailpostfixredirecttestingUbuntu

I am setting up a testing server for a web based application that sends some email notifications.

Sometimes testing is performed with real customer data, and for that reason I need to guarantee that the server is not able to send emails to our real customers while we're testing.

What I want is to configure postfix so that it takes any outgoing email and redirects it to a single email address, instead of delivering to the real destination.

I am running Ubuntu server 9.10.

Thank you in advance

Best Answer

Set up a local user to receive all trapped mail:

adduser mailtrap

You need to add in main.cf:

transport_maps = hash:/etc/postfix/transport
luser_relay = mailtrap

Then create /etc/postfix/transport with this in there:

localhost :
your.hostname.example.com:
* local:mailtrap

Save an then run: postmap /etc/postfix/transport finally restart postfix invoke-rc.d postfix restart

All local email will be delivered normally and external email will be delivered to the local mailtrap account.