Intercept Email from Staging

Intercept email from a Rails app and deliver it to a whitelist of email addresses so the team can preview emails without accidentally delivering staging email to production customers.


# Gemfile
gem "recipient_interceptor"

# config/environments/production.rb
My::Application.configure do
  config.action_mailer.default_url_options = { host: ENV.fetch("HOST") }
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    address: "",
    authentication: :plain,
    domain: "",
    password: ENV.fetch("SENDGRID_PASSWORD"),
    port: "587",
    user_name: ENV.fetch("SENDGRID_USERNAME")

# config/environments/staging.rb
require_relative "production"

Use the EMAIL_RECIPIENTS environment variable to update the comma-separated list of email addresses that should receive staging emails. For example:

heroku config:add EMAIL_RECIPIENTS=""