Tuesday, August 24, 2010

Using fakemail during development

Update: this is far easier: python -m smtpd -n -c DebuggingServer localhost:1025

After a suggestion from my colleague Wietze, i decided to give fakemail a try. Fakemail will act as a mailserver, in that it accepts emails. It saves them to file, however. This eliminates the need for a real mailserver (be it on your local machine or via internet) during development.

To separate it from my default python installation, i create a virtualenv:

$ cd ~
$ virtualenv --no-site-packages venv_fakemail
$ . ./venv_fakemail/bin/activate
(venv_fakemail)$ cd /tmp

Go to http://sourceforge.net/projects/fakemail/files/fakemail-python/1.0beta/fakemail-python-1.0beta.tar.gz/download, save file in ~/Downloads/.

(venv_fakemail)$ tar -xzf ~/Downloads/fakemail-python-1.0beta.tar.gz
(venv_fakemail)$ cd fakemail-python-1.0beta/
(venv_fakemail)$ python setup.py install
(venv_fakemail)$ deactivate
$ ~/venv_fakemail/bin/fakemail.py --host=localhost --port=10025 --path=/tmp
Starting fakemail.py
Listening on port 10025

Now make your program (Plone site) connect to localhost:10025 and send mail:

Incoming mail
Capturing mail to the_dude@example.com
Mail to the_dude@example.com saved
Incoming mail dispatched

The e-mail will be saved as /tmp/the_dude@example.com.1.

easy_installing fakemail-python from pypi didn't work, although it's on pypi.

More info: http://www.lastcraft.com/fakemail.php

1 comment:

Kim Chee said...

This one-liner also works:

python -m smtpd -n -c DebuggingServer localhost:1025

E-mails are shown in the terminal.