(quick install instructions)

If you’re a web programmer … and if you’re not, why are you reading this? … at some point you’ve wished you could integrate email into your webapp. Now, by integrate, I don’t mean sending emails … that’s trivial. Any language you can think of, there’s a library that will let you fire off all the html gibberish that fills your little hearts with joy.

The challenge comes when the little light goes off in your head and you think, “How hard could it be to have my app react to incoming email?” Maybe you’d like people to make forum posts by email, or create mailing lists ( listserv ) dynamically.

The answer used to be hard … very hard. A nightmarish mishmash of postfix, dovecot, procmail, pipes, and the odd custom script would get you something that might, maybe, let you fire off a script when a new email came in. Actually passing email data to your app? Forget it. And after all that, most people would rightly wash their hands of it and say ‘let’s just poll the mail server periodically’ … ick.

Why can’t I just convert emails to HTTP POST’s sent to an endpoint on my webapp? Oh … wait, I can, thanks to Zed Shaw’s LamsonProject.

But first, before going to the trouble of setting LamsonProject up, please be aware that there exist several semi-respectable SAAS companies trying to do this for you:

SendGrid Parse API : Email to POST. I’ve never heard anything bad about SendGrid ( a fair amount of good stuff ) but the it is a sideline to their main business of outsourcing your SMTP server for you.

Email Yak : Email to XML, Email to JSON, Email to POST. In private beta. Don’t confuse with yak mail or yak messenger.

Cloudmailin : Email to POST … “just like a webhook”. In beta.

Honestly, if I had two nickels to rub together I’d probably use SendGrid, but I don’t … so here we are. On with the show!

Installing LamsonProject ( hereafter referred to as Lamson ):

Despite my usual bitchiness, Lamson actually has an excellent walk through for getting started. Read it. Unfortunately for those technically challenged among us, Shaw assumes a certain level of preparation. The following steps should get you set up to follow the setup. Ubuntu specific.

Installing Python ( and easy_install ):

sudo apt-get install python python-dev python-setuptools

( for some reason, easy_install isn’t considered a part of python core in Ubuntu ) Replace default easy_install package lockfile with previous version:

sudo rm /usr/local/lib/python2.6/dist-packages/lockfile-0.9.1-py2.6.egg

sudo easy_install http://pylockfile.googlecode.com/files/lockfile-0.8.tar.gz

As of my writing, easy_install defaults to install 0.9 of lockfile, which has a different API than 0.8 causing failures left and right. Shaw is on it, so it might be worth checking out this thread about it if this post is older than a month. Otherwise this change seems necessary. Now you should be able to:

sudo easy_install lamson

and follow the directions, at least through the 30 second introduction. You’ll probably need to edit your config/settings.py file to have all the ‘host’ settings match ‘localhost’, thus stopping you from being an ‘open host’ … i.e. tramp of the internet before the unittests will pass.

That should be it. You now have a working lamson mailhost … but it’s not set up to do much magic yet. That’s part 2.