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

So a few times now I've been caught out by clients receiving mail sent from the development server because I didn't sanitize the db. So, as an extra safe option, I'd like to ensure that all mail sent from my dev machine is either rejected based on domain or forwarded to myself.

I found a few questions that do a little of what I require;

Postfix on development server, allow only mail to be send to one domain - This looks good and is what I have implemented so far, but the comment on the first answer is correct. Mail sent through Sendmail does not seem to use this setting.

postfix: catch outgoing mail and redirect - THis looked ok, but updating the transport did not do squat for me.

I also looked at address rewriting and read this blog post

I am testing this by calling sendmail on the command line with the -t param like so;

sendmail -t < mail

where the contents of 'mail' are

Date: Tue Oct 11 11:25:22 2011 
Subject: test 

I have been changing the address to be my gmail address and the address. I'm wanting all mail to go to another (work) domain.

So far, I have seen no restrictions come into effect.

/etc/postfix/transport looks like this; : :
* :discard

I have added these lines to

smtpd_recipient_restrictions = hash:/etc/postfix/my_access, reject
transport_maps = hash:/etc/postfix/transport

Please also note I am using the Postfix bundled with MAMP and have been editing through MAMP - File > Edit Template >

share|improve this question
A lot of these are great ideas, but they all seem to miss the one dev machine that wasn't configured properly and just started sending mail. It is usually a good idea to take care of this by either firewalling or transparently proxying all outbound port 25 traffic on the developer networks. – polynomial Oct 11 '11 at 1:49
I agree, but for anybody who installs MAMP, sets up a vhost and starts working on an existing site that uses a false cron (like in my scenario) the problem can occur before they are aware of it. In my case, I'd still like to be able to accept mail to my email address which, if I'm not mistaken, firewalling or proxying would stop? – Christian Oct 11 '11 at 2:49
Did you tried virtual domains? If test-domains have are in countable amout, it can work – Lazy Badger Oct 11 '11 at 4:39
Did I understand you correctly by summarizing: You want all outgoing mails to be blocked/redirected unless they would go to – mailq Oct 11 '11 at 7:28
Thats correct, thanks. – Christian Oct 11 '11 at 21:50

I think, the most simple soluton, if you want to catch all outgoing mail, insert into /etc/postfix/

virtual_alias_maps = static:your_local_user_name
share|improve this answer

You should create a virtual alias file:


virtual_alias_maps = pcre:/etc/postfix/virtual

In /etc/postfix/virtual:

/.*@.*/  $user

Replace $user with the useraccount of your catchall mailbox. Now every single mail sent from that server will be caught in the catchall mailbox

share|improve this answer
Mar 13 12:17:32 *************** postfix/cleanup[22269]: warning: pcre:/etc/postfix/virtual is unavailable. unsupported dictionary type: pcre – Alex R Mar 13 '15 at 12:18
@AlexR sudo apt-get install postfix-pcre – mirabilos Jun 15 '15 at 14:01

Set relayhost for example to some server which refuses relaying - for example your own mail server. This way any outgoing mail will simply be rejected and its delivery notification will go to postmaster mailbox on development computer.

share|improve this answer
Yep, I saw that option, but I still want to receive emails to myself. So, I dont want to 'break' the outgoing mail for everything. – Christian Oct 11 '11 at 5:54

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.