Send and Receive Mail Locally in Rails


1 minute read


One of the first hurdles I ran into when getting started with Rails 4 is sending/receiving mail locally. I’d wired up my basic app and started to sign in for the first time when I realized that I’d given the confirmation email no way to go anywhere. With some authentication gems can loook in the logs for your local rack server and see the confirmation token, but that gets old quickly and you’re quite limited in what you can do.

So I did some looking around and found a great gem called Mailcatcher. Maybe there are more sophisticated solutions out there, but this gem suits my basic needs just fine for now. Check it out!

Setup

Installing Mailcatcher is easy and getting it running is even easier.

  1. gem install mailcatcher
  2. mailcatcher
  3. Go to http://localhost:1080/ to see the UI with received mail
  4. Voila! Send mail through smtp://localhost:1025

If you’re using Rails, then you’ll want to set the following options in config/environments/development.rb

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { :address => "localhost", :port => 1025 }

Related: