gitmyhub

mailcatcher

Ruby ★ 6.8k updated 2y ago

Catches mail and serves it through a dream.

A local fake SMTP server for developers that catches every email your app tries to send and displays it in a browser at localhost:1080, so you can test email sending without ever delivering a real message.

RubyDockerSMTPsetup: easycomplexity 2/5

MailCatcher is a small tool for developers who need to test whether their app sends emails correctly, without those emails actually going anywhere. It runs a local fake email server on your computer. Your app sends mail to that fake server just like it would to a real one, and MailCatcher catches every message and displays it in a simple web page at http://127.0.0.1:1080. No email ever leaves your machine.

This is useful during development because you can see exactly what the app is sending, including the HTML version, the plain text version, and any attachments, without worrying about accidentally emailing real people or filling up an inbox. New messages appear instantly if your browser supports WebSockets, otherwise the page refreshes every 30 seconds.

Installing it takes one command: gem install mailcatcher (Ruby must already be installed). Then you run mailcatcher and point your app's email settings at localhost port 1025 instead of your normal mail server. The README includes specific configuration snippets for Rails, PHP, and Django. A Docker image is also available for people who prefer to run it in a container.

The README explicitly advises against adding MailCatcher to your project's Gemfile, because it can conflict with other gems your application depends on. The recommended approach is to install it as a standalone gem outside your project's dependency list.

A companion command called catchmail makes it easier to route PHP's sendmail-based mail through MailCatcher, since PHP normally calls an external binary rather than connecting to an SMTP server directly. MailCatcher also exposes a simple API so you can fetch message data as JSON programmatically, which can be useful for automated testing.

Where it fits