I want to run a staging copy of a production server on a local environment. The system runs a PHP application, which sends e-mail to customers in various scenarios and I want to make sure no e-mail is ever sent from the staging environment.
I can tweak the code so it uses a dummy e-mail sender, but i'd like to run the exact same code as the production environment. I can use a different MTA (Postfix is just what we use in production), but I'd like something that is easy to set up under Debian/Ubuntu :)
So, I'd like to set up the local Postfix install to store all e-mail in (one or more) files instead of relaying it. Actually, I don't really care how it's stored as long as it's feasible to check the e-mail that was sent. Even a set up option that tells postfix to keep the e-mail in the mail queue would work (I can purge the queue when I reload the staging server with a copy from production).
I know this is possible, I just haven't found any good solution online for what seems like a fairly common need.
Thanks!
I created a new transport with a pipe command that writes e-mail down to a file.
Basically:
email
mkdir /home/email/bin
Place the following script in
/home/email/bin/mail_eater
(this uses PHP, but you can write your own version in any language you like, it just appends stdin to a file):chmod a+x /home/email/bin/mail_eater
touch /home/email/email.txt
chmod a+r /home/email/email.txt
Create a new transport using this file by appending the following line in
master.cf
:Use this as the default transport in
main.cf
:There :)
You could put those domains into
$mydestination
inmain.cf
, so postfix will deliver it locally.You can set up different local users if you want or you can setup a local catch-all address to deliver emails into just one account, more details here: http://www.postfix.org/ADDRESS_REWRITING_README.html#luser_relay
For all domains:
and
/etc/postfix/mydestinations
should containI cannot test right now but it should work.
try (in main.cf):
you can then see queue
postqueue -p
and watch content withpostcat
Depending on your distribution, you could look at "nullmailer". This is a relaying MTA, which relays to another SMTP on your network or remote. This could very well be an invalid SMTP, and in that case it would probably only put it into a queue on a folder on the machine.
On debian and ubuntu this is available as a replacement MTA for your system.
This is copied and slightly modified from my blog http://blog.malowa.de/2011/04/postfix-as-spam-trap-server.html:
You don't even have to configure Postfix to act as a nullmailer. Postfix ships with a neat tool called
smtp-sink
which does the trick. smtp-sink is mainly intended to act as a testing tool for SMTP clients which need a Server to play with. So you can configure it to log the whole conversation or even dump each received mail to a file. The latter is needed for a nullmailer.There is no configuration file to configure smtp-sink. Everything is done via command-line options.
Let's have a closer look to each parameter.
You can find more information in the man page of smtp-sink, but these are the important ones to run a catch-all spamtrap. In this configuration the program accepts any mail with any size from any sender to any recipient with IPv4 and IPv6. The only restrictions are that there are only 256 simultaneous connections possible with 1024 queued connections and the program is flagged experimental. So do not use smtp-sink in a production environment.
The -B option is only valid in newer versions of Postfix. In 2.7.1 it is missing. In 2.8.2 it is present. Somewhere in-between it was introduced.