Mike Rogers on a Snowmobile

Mike Rogers

Web Developer

Mailer Previews in Rails 5

Posted on

One of the best features of Ruby on Rails when developing locally is the Preview Email feature, along with premailer it really makes building out mailers super easy.

However, I like to enable mailer previews in my apps staging environments. Primarily this is so clients can confidently sign off mailers and if required, easily communicate amends.

To achieve this I use the following snippet of code in config/environments/production.rb:

# Enable preview mailers
# Add the ENABLE_MAILER_PREVIEWS to your enviroment to enable.
  config.action_mailer.show_previews = true

  # If you're using RSpec make sure to add the link changing where the previews path is.
  config.action_mailer.preview_path ||= defined?(Rails.root) ? "#{Rails.root}/spec/mailers/previews" : nil

Then I just set ENABLE_MAILER_PREVIEWS to true in my Heroku Apps Config Variables and I'm good.

Share the ♥ by sharing this!

If you want to discuss this post, feel free to tweet me (@MikeRogers0) or drop me an email. Any code samples unless stated otherwise are licensed under the The MIT License (MIT). Spotted a mistake? Send me a pull request :)