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
Set up a local user to receive all trapped mail:
You need to add in main.cf:
Then create /etc/postfix/transport with this in there:
Save an then run:
postmap /etc/postfix/transport
finally restart postfixinvoke-rc.d postfix restart
All local email will be delivered normally and external email will be delivered to the local
mailtrap
account.Better is to create a virtual alias file:
In /etc/postfix/main.cf:
In /etc/postfix/virtual:
You can replace
root
with whichever user you'd like to receive all the outgoing e-mail. This pattern can be tweaked if you want local mail to be delivered normally (without redirection):Original idea found here: Postfix development server - intercept all outgoing mail
Postfix provides something called smtp-sink. By default it blackholes all of the email it receives. Later versions can also be configured to capture the email in files.
This doesn't technically use postfix (but a utility provided by postfix.) It also doesn't technically redirect each email to a single email address. But it does capture all traffic on port 25 and dumps that to a file that can be parsed.