Postfix development server - intercept all outgoing mail
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 mail to be sent to only 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 http://www.postfix.org/ADDRESS_REWRITING_README.html and read this blog post http://rene.bz/redirect-all-outgoing-email-single-account-postfix/
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
To: [email protected]
Subject: test
From: [email protected]
test
I have been changing the address to be my gmail address and the example.com 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;
example.com :
.example.com :
* :discard
I have added these lines to main.cf
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 main.cf through MAMP - File > Edit Template > main.cf
You should install pcre and create a virtual alias file:
apt-get install postfix-pcre
in mail.cf:
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
I think, the most simple soluton, if you want to catch all outgoing mail, insert into /etc/postfix/main.cf
virtual_alias_maps = static:your_local_user_name