Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 16 down vote accepted

Set up a local user to receive all trapped mail:

adduser mailtrap

You need to add in

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

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

localhost :
* 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.

share|improve this answer
This is exactly what I was looking for... thank you! – thatjuan Feb 12 '10 at 23:29
Works for me but only after I added luser_relay = xxxxx in Without this the emails would bounce. – Alex R May 29 '11 at 0:57
When using Ubuntu, you can also restart Postfix with sudo service postfix restart. The location of your file mentioned above is /etc/postfix/ When first installing and setting up Postfix, you can use the Local only installation option. – mtnorthrop May 25 '12 at 9:12
on MAC you should run postmap hash:/etc/postfix/transport and sudo postfix stop, sudo postfix start – Bang Dao Jul 23 '13 at 8:50

Better is to create a virtual alias file:

In /etc/postfix/

virtual_alias_maps = pcre:/etc/postfix/virtual

In /etc/postfix/virtual:

/.*@.*/ root

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):

/.*@(?!hostname\.localdomain$).*/ root

Original idea found here: Postfix development server - intercept all outgoing mail

share|improve this answer
Note you might need to sudo apt-get install postfix-pcre beforehand, to avoid… surprises. – mirabilos Jun 15 '15 at 14:01

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.

share|improve this answer
How does one invoke smtp-sink? The one manpage I found online made it look like it's a normal program, but if it came with postfix it's not installed on my system (OSX 10.6). How would I run this a service? – Chrisbloom7 Nov 22 '10 at 1:26
There is a manpage for smtp-sink. But some parameters are described here, too: – mailq Aug 16 '11 at 9:30

Your Answer


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.