Ruby on Rails / Rubygems – immediate mail delivery in development

Ruby on Rails / Rubygems – immediate mail delivery in development February 20, 20181 Comment

Emails are very important part of almost every Ruby on Rails application so it’s important to test them well during the development process. Setting up a local mail server may be a little problematic and time-consuming process but there is another way to test our emails immediately. There is a letter opener gem which would handle emails for you and open them in your browser each time you will send them in your app.


We have to add it to our Gemfile and then run bundle install:

gem "letter_opener", :group => :development

We want this gem to be available only in the development environment so we have to specify a group to which this gem belongs. If you already have development group defined then just add this gem inside it.


We have our gem installed but now we have to let know Rails that we want to use it for the emails delivery. In order to do this, open config/environments/development.rb file and add the following line:

config.action_mailer.delivery_method = :letter_opener

And that’s it! Try now to trigger one of your emails by using your app or simply from console level. What is nice you can preview both HTML and plain versions of your e-mail. Each opened email would be saved in tmp directory so you can easily clear it anytime you want.

If you want to use this gem without rails or you want to check more advanced configuration, visit gem homepage on github

Download free RSpec & TDD ebook

Do you want to earn more or jump to the next level in your company? Do you know that testing skills are one of the most desired skills? There is only first step: start testing and do it right. My ebook can help you. Subscribe to the newsletter to get a free copy of the book.

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *