Delivering All Email From Staging To A Group Email Address

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

Dan Croak Developer

Sharpen your programming skills by completing coding exercises that are reviewed by other developers at Upcase today.