Home » Posts tagged "mail"

How to catch and test sent e-mails in your app

A nice gem (literally, it’s a Ruby program) I stumbled upon yesterday is called MailCatcher. Using MailCatcher you can catch all the mail that’s being sent by the app you’re developing and (re)view their contents.

MailCatcher makes this possible by running (or rather being) a simple SMTP server. All you’ve got to do is direct your app to use the SMTP server provided by MailCatcher. Mail sent with this SMTP server stays inbound so you don’t have to worry a test mail is receiving by a customer.

It also provides a neat web interface in which you can review the mails that have been sent. Aside from viewing the contents of the mail you can also do further inspection on it by taking a deeper look into the source of the mail to view headers and such.

Screen shot 2011-06-23 at 11.39.03 PM(source: mailcatcher.me)

By using WebSockets the webinterface immediately updates when a mail has been sent. You can also download the e-mail to load it up in your e-mail client. This can be useful to review HTML based e-mails to see how they render.

If you’re using Vagrant I suggest you add the port the webinterface runs on to the forwarded ports list. Also run mailcatcher with --http-ip 0.0.0.0 so you can reach the webinterface from the host OS.