Dan Poltawski's blog

Testing email features with Mailcatcher

Email is one of those areas of software which is a tricky to get a good test setup and thus rarely gets tested well. In Moodle we have quite a few flags which can be used for development but I’ve never quite felt happy with it. In a previous job we ended up setting up Exim to intercept all messages and write to a file which could be read from a browser. It was pretty complex, a pain to setup and you ended up just looking at the message source.

So I was delighted this week when I came across across MailCatcher via One Thing Well. As it says on their site: MailCatcher runs a super simple SMTP server which catches any message sent to it to display in a web interface.

The instructions are simple:

  1. gem install mailcatcher
  2. mailcatcher
  3. Go to http://localhost:1080/
  4. Send mail through smtp://localhost:1025

So in my Moodle config.php I set: $CFG->smtphosts = 'localhost:1025'; then start doing some email-generating operations and voilà:

mailcatcher

Everything you need is availble in one place, source view, html view, plain text view - right in your browser. Great job Samuel Cochran!