recipient_interceptor icon indicating copy to clipboard operation
recipient_interceptor copied to clipboard

Add email and domain whitelist options

Open thomasklemm opened this issue 10 years ago • 7 comments

@croaky Thanks for this great gem.

This PR adds two options:

  1. Optionally white-list emails:
Mail.register_interceptor RecipientInterceptor.new(
  ENV['EMAIL_RECIPIENTS'],
  email_whitelist: ['[email protected]']
)
  1. Optionally white-list domains:
Mail.register_interceptor RecipientInterceptor.new(
  ENV['EMAIL_RECIPIENTS'],
  domain_whitelist: ['example.com']
)

If one or more of the original recipients match the email white-list or domain white-list, the email's to field will not be overridden. However, non-white-listed emails will be removed from the email's to field.

thomasklemm avatar Apr 30 '14 11:04 thomasklemm

+1, great to whitelist exception's email (ie. when using exception_notification gem). Thanks to both of you for your work.

chab avatar Sep 24 '14 21:09 chab

@croaky - is there any chance on merging this PR?

DamirSvrtan avatar Apr 09 '15 23:04 DamirSvrtan

:+1:

kevinwmerritt avatar Jul 24 '15 04:07 kevinwmerritt

Hi folks. Making sure I understand the use case:

While we could make EMAIL_RECIPIENTS go to [email protected],[email protected],[email protected], the whitelist change is more convenient, less likely to be forgotten by the team if we use example.com in the domain_whitelist?

The email_whitelist is more convenient because we can unset EMAIL_RECIPIENTS and only [email protected] will get the email instead of kevin, dan, and thomas?

croaky avatar Jul 24 '15 23:07 croaky

Hi @croaky,

I'll let others respond about "domain_whitelist". In our case, we only use the "email_whitelist" option.

Here's what we have in our staging.rb:

  Mail.register_interceptor RecipientInterceptor.new(
    '[email protected]', 
    email_whitelist: %w([email protected])
  )
  • All [email protected] emails are forwarded to product owner+testers so that they can review all public emails sent from the website without risking emailing real users.
  • All [email protected] emails are forwarded to developers only. (via https://github.com/smartinez87/exception_notification gem)

Without this PR, product owner+testers would receive all exceptions emails as well.

Thanks!

chab avatar Jul 25 '15 09:07 chab

@croaky Thanks for the handy library. You understand the use cases correctly. A domain whitelist would be nice so test users on a certain domain could receive email at their own address instead of the catch all.

kevinwmerritt avatar Jul 25 '15 17:07 kevinwmerritt

@croaky Just came across this PR and this interests me. I guess I thought RecipientInterceptor worked like a whitelist this whole time, when it appears that it completely overrides to: for all emails. Unfortunately this means that staging isn't very realistic if you have different mailers that send emails to different people. I'd be curious if you would approve changing the behavior of this gem to act more like a whitelist?

mcmire avatar Dec 23 '16 00:12 mcmire