Low commit activity in last 3 years
A long-lived project that still receives updates
Use RecipientInterceptor when you don't want your Ruby program to accidentally send emails to addresses other than those on a whitelist which you configure. For example, you could use it in your web app's staging environment.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
 Project Readme

recipient_interceptor

Use this Ruby gem to avoid emailing your users from non-production environments.

# Gemfile
gem "recipient_interceptor"

# config/environments/staging.rb
Mail.register_interceptor(
  RecipientInterceptor.new("staging@example.com")
)

Email will be intercepted and delivered to the provided address with headers X-Intercepted-To, X-Intercepted-Cc, and X-Intercepted-Bcc added.

Configuration options and examples

Deliver intercepted email to multiple email addresses:

Mail.register_interceptor(
  RecipientInterceptor.new(["one@example.com", "two@example.com"])
)

Use a comma-delimited string:

Mail.register_interceptor(
  RecipientInterceptor.new("one@example.com,two@example.com")
)

Use an environment variable:

# heroku config:set EMAIL_RECIPIENTS="one@example.com,two@example.com" --app staging
Mail.register_interceptor(
  RecipientInterceptor.new(ENV["EMAIL_RECIPIENTS"])
)

Prefix the subject line with static text:

Mail.register_interceptor(
  RecipientInterceptor.new(
    ENV["EMAIL_RECIPIENTS"],
    subject_prefix: "[staging]",
  ),
)

Prefix the subject line with contents from the original message:

Mail.register_interceptor(
  RecipientInterceptor.new(
    ENV["EMAIL_RECIPIENTS"],
    subject_prefix: proc { |msg| "[staging] [#{(msg.to + msg.cc + msg.bcc).sort.join(",")}]" }
  ),
)

The object passed to the proc is an instance of Mail::Message.

Contributing

Fork the repo.

bundle
bundle exec rake

Make a change. Run tests. Open a pull request. Discuss/address any feedback with maintainer. Maintainer will merge.