recipient_interceptor
recipient_interceptor copied to clipboard
Add email and domain whitelist options
@croaky Thanks for this great gem.
This PR adds two options:
- Optionally white-list emails:
Mail.register_interceptor RecipientInterceptor.new(
ENV['EMAIL_RECIPIENTS'],
email_whitelist: ['[email protected]']
)
- 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.
+1, great to whitelist exception's email (ie. when using exception_notification gem). Thanks to both of you for your work.
@croaky - is there any chance on merging this PR?
:+1:
Hi folks. Making sure I understand the use case:
- I've got a Rails app that I'm testing on staging, using
RecipientInterceptor
. - I have the
EMAIL_RECIPIENTS
environment variable set to go to[email protected],[email protected]
- I test something on the Rails app that should deliver an email to
[email protected]
. It will instead be delivered to[email protected],[email protected]
.
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
?
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!
@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.
@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?