Fakemail FTW!
What is fakemail?
From the fakemail homepage:
fakemail is a fake mail server that captures emails as files for acceptance testing. This avoids the excessive configuration of setting up a real mail server and trying to extract mail queue content.
If you have had to test applications that send e-mails, for example as part of a web sign up process, you will know what an involved and tricky exercise that can be. Usually you have to sign up with a special e-mail address, have the mail go to the mail server and then read it back into the test with a POP/IMAP client. There are several downsides to this approach; you need to install extra software to interact with the POP server, you suffer from spurious failures due to reliance on external infrastructure, and it is very very slow.
Fakemail works by intercepting the mail before it leaves the machine by replacing your Mail Transfer Agent (MTA). It’s a simple script run from the command line that you can launch from within your test framework.
Why Should I Use fakemail?
The real question is why aren’t you using fakemail. I didn’t know of fakemail before I started at SugarCRM, but now I’m glad that I do. At Sugar we use fakemail on all of our test and development instances. By using fakemail it provides a way to test all of our scripts that send emails but not actually send the emails out. What it does in turn is send the email (headers and all) to a folder specified in the config of the fakemail setup. We happend to send ours to /tmp/<instance name>/ since we have multiple instances running on the same machine.
How do I Setup fakemail
fakemail comes in two flavors: Python and Perl. They both work the same but what this allows you to do is pick your poison on which language you are more comfortable with.
Once you install fakemail to start it up just issue the following command (PERL version)
fakemail --host=localhost --port=10025 --path=/tmp
Now it’s running. To test it out just run telnet into localhost port 10025
telnet localhost 10025 Connected to localhost.localdomain (127.0.0.1). Escape character is '^]'. 220 uno.home SMTP Net::Server::Mail (Perl) Service ready
To test it use the following commands
HELO mailer 250 Requested mail action okay, completed MAIL From: me@here 250 sender me@here OK RCPT To: you@there 250 recipient you@there OK DATA 354 Start mail input; end with . A-header: Sample header Hello . 250 message queued QUIT 221 uno.home Service closing transmission channel
After this sequence we can stop the fakemail terminal with a Control-C to interrupt the process. Because we set the fakemail path to the local directory, we should see a file labelled “you@there.1″. Here is the contents of that file…
A-header: Sample header Hello
You should now be ready to use fakemail to make your testing easier.
Don’t forget to check the fakemail page for more information.
read more

