20 June 2013

From time to time I need to work with outgoing mails: change templates, make sure they display correct data etc. You could go with some full blown MTA like postfix and it’s actually pretty easy to install and configure for outgoing mail sending. I personally tend to not install MTA on my dev box, since I may accidentally send emails to clients..

What I use instead are two little tools called Nullmailer and Fakemail

Nullmailer

You can think of nullmailer as sendmail wrapper which just relies messages to another mail host. Most mail functions ( like PHP mail() ) expect sendmail binary installed by MTA, in our case nullmailer provides sendmail binary and as the result all mail flows through it to the mail host you configure.

On Ubuntu you can install Nullmailer pretty easily, just type:

sudo apt-get install nullmailer

Then configuration part - in most cases it’s pretty easy. On Ubuntu configs are in /etc/nullmailer.

For my dev box I just added one line to the config /etc/nullmailer/remotes:

localhost smtp ( remember I use Fakemail to capture mails and write them to a folder )

and then restart nullmailer

sudo /etc/init.d/nullmailer restart

That’s about it, at this point you should have Nullmailer forwarding mail to your local smtp port. Read on to find out how to capture outgoing emails on that port.

Tip: Sometimes it could be useful to purge nullmailer queue, that could be the case when you machine was running for a while and a bunch of mails got queued. After you connect Fakemail - nullmailer will try to deliver those. If you don’t want that - just delete those messages from /var/spool/nullmailer/queue/ ( Debian location ).

Fakemail

Now that we have Nullmailer forwarding mails to our smtp port ( usually 25 ) we need to capture and write those to a folder, so we could actually do some work on our newsletters.

Introducing Fakemail:

A fake mail server that captures e-mails as files for acceptance testing. This avoids the excessive configuration of setting up a real mail server and trying to extract mail queue content.

To install, just download archive from sourceforge ( I posted a link at the beginning of the post ) or google it. Then all you need to do is launch it. I use following command to start the service:

sudo /var/www/fakemail-python-1.0/build/scripts-2.7/fakemail.py --port 25 --path /tmp/mails

Make sure you specify your own path to the fakemail install, also you need to create a directory where your fake mails will be stored.

At this point you should be able to send mails from your scripts and debug them on your dev box!

Enjoy.

Contact me on Codementor


Some popular ones

My books recommendations

Great book for operations people. Helped me to design and build solid deployment pipelines. Awesome advices on automated testing as well. The author advocates against feature branches, every commit goes to master! Scary? I know, but it actually makes sense once you get the idea. Read the book to find out more.

One of those rare books where every word counts!

Classics from John Allspaw who is SVP of Infrastructure and Operations at Etsy (and used to work for Flickr). The book covers very important topics like metrics collection, continuous deployment, monitoring, dealing with unexpected traffic spikes, dev and ops collaboration and much more. Def recommend if you are starting out in the operations field or been doing it for a while ( in latter case you probably read this book already :).

This book is must read for every software engineer, no matter which language you use! It will change your perspective on writing code. I was amazed by the quality of material - very detailed and up to the point.

"The only way to make the deadline -- the only way to go fast -- is to keep the code as clean as possible at all times."


blog comments powered by Disqus