To use the gem in staging or pre-production environments to intercept emails:
- Move the gem out of the
development group in your Gemfile (e.g., place it in the top-level or a specific group). - Set
config.action_mailer.delivery_method = :letter_opener_web in the appropriate config/environments/<env>.rb. - Enable the route in
routes.rb for that environment.
Note for Heroku users: This will only work if your app has exactly one Dyno and does not send emails from background jobs.
# Gemfile
gem 'letter_opener_web'
# routes.rb
Your::Application.routes.draw do
# For dedicated staging environments
mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.staging?
# For environments using RAILS_ENV=production in staging
mount LetterOpenerWeb::Engine, at: "/letter_opener" unless ENV["PRODUCTION_FOR_REAL"]
end