Need help with recipient_interceptor?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

croaky
222 Stars 16 Forks MIT License 37 Commits 2 Opened issues

Description

Intercept recipients when delivering email with the Mail gem.

Services available

!
?

Need anything else?

Contributors list

# 7,316
Ruby
Shell
twelve-...
Rails
30 commits
# 255,166
stripe
braintr...
GraphQL
HTML
1 commit
# 164,117
Ruby
Algolia
Rails
sequel
1 commit
# 69,291
Ruby
fixture...
rubygem...
Rails
1 commit
# 322,956
Ruby
1 commit
# 26,648
Rails
Compose...
Objecti...
watchos
1 commit

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("[email protected]") )

config/environments/production.rb

My::Application.configure do config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { address: ENV.fetch("SMTP_ADDRESS"), # example: "smtp.sendgrid.net" authentication: :plain, domain: ENV.fetch("SMTP_DOMAIN"), # example: "heroku.com" enable_starttls_auto: true, password: ENV.fetch("SMTP_PASSWORD"), port: "587", user_name: ENV.fetch("SMTP_USERNAME") } end

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(["[email protected]", "[email protected]"])
)

Use a comma-delimited string:

Mail.register_interceptor(
  RecipientInterceptor.new("[email protected],[email protected]")
)

Use an environment variable:

# heroku config:set EMAIL_RECIPIENTS="[email protected],[email protected]" --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.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.