Capture all sent mail locally with Postfix
For development, you don't want any e-mail sent to the outside world, but you do want to be able to see all mail your sites or application try to send. Here is a configuration of Postfix to do that.
The trick is to BCC everything to a local user, and discard without error any other sending.
This is based on several guides and Q&As online but well, none of them worked for me, so here's exactly what i did (minus all the missteps).
If Postfix is already installed, you can
sudo dpkg-reconfigure postfix to make certain it is configured for Local only, or if you don't have Postfix yet choose the same options after
sudo apt-get install postfix.
sudo vi /etc/postfix/main.cf
In main.cf add:
transport_maps = hash:/etc/postfix/transport always_bcc = root@localhost
Not sure if it's necessary, but i read that Postfix prefers to not actually deliver mail to root. So my aliases has a line to use my own account instead of root:
sudo vi /etc/aliases
# See man 5 aliases for format postmaster: root root: ben
sudo vi /etc/postfix/transport
localhost : onyx : * discard:
(Where onyx is the name of my computer and is probably not at all needed here.)
This is key, do not forget to create the transport.db file from the transport mapping text file you just edited:
sudo postmap /etc/postfix/transport
And restart Postfix:
sudo service postfix restart
To see what's going on while getting this to work.
tail -f /var/log/mail.log
To see your mail as it gets delivered:
sudo tail -f /var/mail/ben