It cannot be emphasized enough how useful it is to be able to catch all outgoing e-mail from a system when you are developing and testing e-mail based functionality. This small guide shows you how I typically setup a Postfix/Dovecot combo for my local development environment that will route all e-mail being sent from your computer, to a local user account.
In this guide I am using Linux Mint as operating system, but any Ubuntu based distribution should work fine. What makes this sort of Ubuntu specific is the software package dovecot-postfixÂ and that makes this setup really fast to do. You could install Dovecot and Postfix from separate packages as well, but that would require additional configuration that I will not cover here.
First of all, lets install the Dovecot and Postfix servers:
sudo apt-get install dovecot-postfix
This will install some additional packages required as well. During the installation you will get to select what type of Postfix setup to install. Choose “Internet Site” and continue.
Next question from the Postfix installation requires you to provide a system mail name. The installation has provided one for you. So just accept that but make sure to remember it, because you will need it later.
The installation will finish and you now have a running Dovecot and Postfix installation.
Now you need to configure Postfix so it routes all e-mail sent from it, to a local account that you can access either though POP3 or IMAP.
Open up the main configuration file:
cd /etc/postfix sudo nano main.cf
Add the following two lines at the end of
main.cf file, but be sure to replace “puffy” with the name of the local user that should receive all e-mails:
transport_maps = hash:/etc/postfix/transport luser_relay = puffy
Next up is to create the
sudo nano transport
In this file we define that outgoing e-mails should be delivered to a local account rather then actually sending it to its addressed recipient. Make sure you replace “mintdev” below with the system mail name that Postfix suggested in the installation. Also replace “puffy” with the local user name previously set in the luser_relay setting:
localhost : mintdev : * local:puffy
Save that file and convert it to a Postfix lookup table and then we can restart the Postfix server:
sudo postmap transport sudo service postfix restart
Now you have it all working and all mail sent through “sendmail” command or the local SMTP server will be routed to the local user account you chose. You should also be aware that both Dovecot and Postfix both are listening to the 0.0.0.0 interface. If you do not want that you might want to change it to 127.0.0.1 or some other address of your choice.
You can use any IMAP or POP3 capable e-mail client to access all e-mails that has been routed to the local account. If you have the e-mail client on the same machine as the Dovecot installation, you can use these settings:
Server Type: IMAP Mail Server Server name (address): local Port: 143 Connection security: STARTTLS Username: puffy Password: (the password of your local user account)
Thats it, happy e-mailing!
Feel free to leave a comment using the form below.