Intercept Email from Staging

Intercept email from the staging environment of a Rails app and deliver it to a group email address using croaky/recipient_interceptor. This lets the product team preview emails without accidentally delivering staging email to production customers.

In Gemfile:

gem "recipient_interceptor"

In 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")

In config/environments/staging.rb:

require_relative "production"


Use the 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
Edit this article