Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

Our production servers need to mass-mail our clients on a regular basis. That works perfectly. The problem is that our 'staging' environment also sends out the emails to our clients when we test new features and forget to override the actual client emails throughout our numerous databases and tables.

A solution came to mind: could I configure Postfix in a way that all outgoing emails are blocked unless they are destined to our own domain when we are on our staging/test servers.

I googled around and found how to reject specific domains, but have not found the way to reject them all except one. Any help will be appreciated.

share|improve this question
up vote 8 down vote accepted

You can add a transport map in

transport_maps = texthash:/etc/postfix/transport

Then edit /etc/postfix/transport with your favorite editor and add this: smtp:
* error:only mail to * will be delivered

This will bounce every mail with recipients other than * If you need to be able to change the transport_map on the fly use hash instead of texthash, but you have to use postmap on the file once you changed it to update the corresponding .db file and so postfix notices it has changed. If you don't want to bounce other mails use this instead: smtp:
* discard:
share|improve this answer
Doesn't seem to have worked... is there already supposed to be a 'transport' file ? All my emails are blocked, including the ones. – IanBussieres Feb 2 '12 at 21:27
That depends on the before you added the transport_maps above. If there is no transport_maps in the is by default empty. If there is one remove that one so only the added on remains. What do you mean by "All my emails are blocked" ? Do you get bounces, are they just not getting delivered? Do they pile up in postqueue? Or are they rejected directly when trying to send them? – lsmooth Feb 2 '12 at 23:46
There were no transport_maps before adding the one you suggest. Regarding the blocked emails, they hang in the queue: -Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient------- 5D2BB58076 223 Fri Feb 3 10:06:28 root – IanBussieres Feb 3 '12 at 15:08
I'm sorry to bump this @Ismooth, I just wanted to make sure you had posted the answers to your follow-up questions. I've tested once more, the problem persists. – IanBussieres Feb 7 '12 at 21:50
Ah sorry, is there also a reason listed in postqueue -p ? – lsmooth Feb 7 '12 at 23:49

if is your internal domain you want to edit the transport file to include just :

and not smtp:


otherwise with that one change this worked great for me. Thanks lsmooth!

share|improve this answer
For some reason this isn't working for me either... But as soon as I comment the line 'transport_maps = texthash:/etc/postfix/transport' in it starts working fine. – IanBussieres Feb 10 '12 at 18:37

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.