A “testing” email server which doesn’t send out any emails
Problem
I need an email server for testing. It accepts email just like a real one, but does not actually send any email out to the real world. I need to be able to see the emails that it is not sending.
Solution
For my immediate problem, all the mail is going to the same user@domain so I can get away with this:
- install Postfix MTA
- accept mail to target domain
- rewrite mail to target for a local user
It is not the solution I want however. That would be a server which will accept and route ALL emails regardless of destination to a single local email address. This goal is opposite to the fundamental goal of an email server, so there doesn’t seem to be any option with big lettering which I can turn on to make this happen. So I’ll come back and edit this post when I’ve solved this problem for real. For the meantime my application is sending everything to “peter@johnmee.com” and I will redirect it to the “john” account of the test machine.
1. Install postfix MTA
For Ubuntu/Debian/Linux
sudo apt-get install postfix
2. Accept mail to target domain
Edit /etc/postfix/main.cf
Add the target domain to the list in “mydestination”
mydestination = lappy, localhost.localdomain, localhost, johnmee.com
3. Rewrite mail to target for a local user
Edit /etc/aliases
Map the target user to an actual user
peter: john
Then rehash the aliases, and reload postfix
newaliases
postfix reload
And so all mail sent to peter@johnmee.com is rerouted to john@localhost. Great.
Except that I still need to be able to see the email it sent and ubuntu doesn’t seem to have any mail client installed by default. Certainly none that is commandline driven and uses Maildir format.
So for this requirement I’ve installed “cone”, which is sufficiently close to Pine, and totally whips classic mail/mailx, well enough to keep me happy.
sudo apt-get install cone
Other notes of value
To see what postfix has in its delivery queue(s)
postqueue -p
To delete an email from postfix delivery queue(s)
postqueue -d <queue-id>
To watch whatever the heck the mail server is up to
tail -f /var/log/mail.log
John is a freelance programmer living in Sydney Australia. He blogs whatever takes his fancy; computing tips, travel letters, and random stuff from his life. He does it primarily to learn and demonstrate the running of a website.
I found a solution that might fit your problem:
I wanted to send mail from a machine that would not be able to have any physical connection to the internet - transporting mail should be done via removable media. And I wanted to be able to check the mails when debugging the software that sent them.
I found some documentation for qmail that described how to put all outgoing mail into a local Maildir (somewhere in http://www.jochen-solbrig.de/freebsd/dialuplan/dialuplan.html, IIRC) and send mail from there.
After browsing the docs I found that could do the same with postfix by defining a transport in /etc/postfix/master.cf:
ppp unix - n n - - pipe flags= user=ppp argv=/usr/bin/procmail -d ppp
and make it the default in main.cf:
default_transport=ppp
Obviously, a user named “ppp” had to be added to make that work. Now all outgoing mail gets dropped into ppp’s Maildir.
This user account looks like a normal user account to the IMAP server installed on the machine and the mails can be accessed (and deleted) from any IMAP-capable mail client.
Harald, awesome contribution. Thanks.
Actually I needed a solution for this yet again soon after the initial posting. That server was only running the default Sendmail. From memory, I added the domains I wanted to trap to a sendmail config file, then played with the aliases so that it appended all that email to a specified file. It worked rather well in that I could just tail the file and watch the raw emails accumulate.
I’ll have to dig that solution out and post its details sometime sooner than later. Thanks again.