A “testing” email server which doesn’t send out any emails

December 27th, 2008

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:

  1. install Postfix MTA
  2. accept mail to target domain
  3. 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
  1. Harald.Stürzebecher
    April 10th, 2009 at 02:34 | #1

    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.

  2. April 13th, 2009 at 16:21 | #2

    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.

  3. Paul
    July 24th, 2009 at 13:09 | #3

    John, I don’t know if (a) you are still looking or (b) you have access to a Windows box. If so, smtp4dev (http://smtp4dev.codeplex.com/) is pretty great, I had the same need myself.

    Now, to continue looking for somewhere near Melbourne that can let me try out a frickin’ Steelcase Leap chair.

  1. No trackbacks yet.