6

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.

3 Answers 3

9

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:
6
  • 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. Feb 2, 2012 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, 2012 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 protected] Feb 3, 2012 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. Feb 7, 2012 at 21:50
  • Ah sorry, is there also a reason listed in postqueue -p ?
    – lsmooth
    Feb 7, 2012 at 23:49
1

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!

1
  • 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. Feb 10, 2012 at 18:37
-1

This looks incorrect. I used this setup to limit outgoing domains.

main.cf: transport_maps=hash:/etc/postfix/transport

and transport contains following lines:

domain1.foo smtp:ip.address.of.relay.host
domain2.foo smtp:ip.address.of.relay.host
* discard:

and then just postmap /etc/postfix/transport and reload the postfix. that worked fine for me.

Eero

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .