I sometimes work on websites where sending email is a central task. To be able to efficiently test my code on my Ubuntu development machine, I have created a simple setup from the following requirements:
- No mail should reach the internet
- I should be able to quickly read every message that is “sent” from PHP
The strategy is to use Postfix to catch and save messages (and enable
mail() at all), and Mutt to read them without any fluff.
sudo apt-get install postfix
Most of the configuration of Postfix resides in
/etc/postfix/main.cf. Add the following lines:
# Redirecting to local mailbox home_mailbox = .mail/ virtual_mailbox_domains = regexp:/etc/postfix/domains.regexp virtual_alias_maps = regexp:/etc/postfix/virtual.regexp
Also create the referenced files
/.*/ arildm # Your username
Reload the configuration:
sudo postfix reload
Here we’re telling Postfix to be the end destination for all mail and redirect it to the local user arildm (which is me).
home_mailbox, many guides that I found use
Mailbox/. I suppose that’s more or less standard, but I don’t like unnecessary capitalisation nor non-hidden directories in my home directory (because that’s where the mail has to go if you use maildir on Ubuntu, as far as I know). By ending the parameter value with a slash, we tell Postfix to use the mailbox format rather than mbox. That has the advantage that each message is written to its own file, which facilitates manual inspection a lot.
Test the configuration:
echo I am a mail | sendmail firstname.lastname@example.org find ~/.mail
Mutt is a console email client. Install it:
sudo apt-get install mutt
~/.muttrc and add:
set mbox_type=maildir set folder="~/.mail" set mask="!^\\.[^.]" set mbox="~/.mail" set spoolfile="~/.mail"
If I understood correctly, by default Mutt reads mail from the spool (usually
/var/mail/$USER) and moves read messages to
~/mbox. The lines above sets both these paths to
Now run Mutt and expect to see the previously sent test message.
Mutt navigation at a glance:
- next message
- previous message
- open message
- show headers (whole raw message)