Delivering All Email From Staging To A Group Email Address

All email from the staging environment of a Rails app can be intercepted and delivered to a group email address. This avoids accidentally delivering staging email to production customers and lets the product team see all the emails that are being sent to customers.


We’ll use recipient_interceptor.


gem 'recipient_interceptor'


if Rails.env.staging? || Rails.env.production?
    address: '',
    authentication: :plain,
    domain: '',
    password: ENV['SENDGRID_PASSWORD'],
    port: '587',
    user_name: ENV['SENDGRID_USERNAME']


require Rails.root.join('config/initializers/mail')

My::Application.configure do
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = MAIL_SETTINGS

Also in config/environments/staging.rb:


Use the ENV['EMAIL_RECIPIENTS'] environment variable to update the list of email addresses that should receive staging emails. For example:

heroku config:add EMAIL_RECIPIENTS="" --remote staging

Gmail filter

Depending on the app, this may generate thousands of emails a day. Avoid spamming yourself by setting up a Gmail filter for emails sent to

Pair with one of our expert developers to level up your skills with Coaching by thoughtbot. Save time learning best practices and techniques for reducing technical debt in Ember, Ruby, Haskell, and Go in 1-on-1 sessions tailored to your goals.