Debugging emails in an application is usually very tedious. Some frameworks and libraries try to help you with debugging, but even the best tools usually fail when it comes to batch sending mails.
The best way to debug emails on your local development machine is having a small mailserver installed that does not actually send mails in the wild, but collects them locally.
It's not as hard as you might expect:
1. Install and configure exim
Exim is a small and very lightweight message transfer agent (MTA). To install it on Debian/Ubuntu type:
To configure exim call
General type of mail configuration:
local delivery only; not on a network
Delivery method for local mail:
Maildir format in home directory
Split configuration into small files:
Next up create the file
/etc/exim4/conf.d/router/175_exim4-config_catchall and place the following content in it (replace
<username> with your username):
Restart exim afterwards:
To test if the configuration works run
You should find a new file in
~/Maildir/new that contains your send mail.
2. Install Mutt
Install mutt from the package manager
and create the configuration file
/etc/Muttrc.d/maildir.rc with this content
Now you can call
mutt to see your mails.
Shortcuts for mutt
?shows the help
$deletes all mails
~d>1dremoves all mails older than one day
3. Configure your application
Just tell your application to use
sendmail to send the mails. Usually the PHP function
mail() is configured to use
sendmail too. As this is the easiest way for libraries to send emails, it is available in most libraries.
You can also use SMTP to send emails through
localhost on port