Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

2 Answers 2

up vote 7 down vote accepted

You can add a transport map in main.cf:

transport_maps = texthash:/etc/postfix/transport

Then edit /etc/postfix/transport with your favorite editor and add this:

example.com smtp:
* error:only mail to *@example.com will be delivered

This will bounce every mail with recipients other than *@example.com. 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:

example.com 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 @example.com ones. –  IanBussieres Feb 2 '12 at 21:27
    
That depends on the main.cf before you added the transport_maps above. If there is no transport_maps in the main.cf 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 email@example.com –  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 example.com is your internal domain you want to edit the transport file to include just

example.com :

and not

example.com smtp:

per http://www.postfix.org/transport.5.html

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 main.cf it starts working fine. –  IanBussieres Feb 10 '12 at 18:37

Your Answer

 
discard

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.