Last Updated: February 25, 2016
· ttoni

Mailing in staging environment

When in staging environment, one does not flood the user's inbox with pointless staging emails. A good option is to redirect all emails sent while in staging to a specific email address.

Based on these two approaches: DHH and thoughtbot. And using the gem recipient_interceptor.

First add recipient_interceptor to Gemfile.

Example of a production config file:

Appname::Application.configure do

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.smtp_settings = {
    :address   => "",
    :port      => 25, # ports 587 and 2525 are also supported with STARTTLS
    :enable_starttls_auto => true, # detects and uses STARTTLS
    :user_name => ENV['MANDRILL_USERNAME'],
    :password  => ENV['MANDRILL_PASSWORD'], # SMTP password is any valid API key
    :authentication => 'login', # Mandrill supports 'plain' or 'login'
    :domain => '', # your domain to identify your server when connecting


And this would be the staging config file:

# Based on production defaults
require Rails.root.join("config/environments/production")

  subject_prefix: '[STAGING]'