-
Notifications
You must be signed in to change notification settings - Fork 937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add OverrideRecipientSMTP delivery method #423
Conversation
Use the OverrideRecipientSMTP delivery method when you don't want your program to accidentally send emails to addresses other than the overridden recipient which you configure. An example use case is in your web app's staging environment, your development team will receive all staging emails without accidentally emailing users with active email addresses in the database.
If you're using ActionMailer, the mail_safe gem does this more flexibly: |
@dball Thanks for the link. I hadn't seen that one but have seen a number of similar solutions: https://gist.github.com/138420 It's definitely a common need! It's common enough that I hope it will be accepted into the Mail gem, which I like as the home for this because:
|
+1! I am the one of "the others involve some dirty monkey-patching" |
-1 this doesn't seem like something that should go into the core gem but be extracted into a plugin. If this is a Rails application you should have a specific |
+1 |
Nudge @mikel. Your opinions on this pull request? |
Hi there, I like this, however, I think we should include the original values some how in the resulting email. ie, setting to, cc and bcc to nil is fine, however, perhaps we should store the original values as Make this change and appropriate tests and I think we can merge this in. |
Better yet, leave the message's recipients intact! Check out #477 to set the SMTP envelope recipient directly: Side note: you can do this on your development machine using Postfix, too. In
Create That'll rewrite the recipient on every SMTP envelope to your catchall address. |
Also! This is a better fit for an interceptor than a delivery method: class CanonicalEnvelopeRecipientInterceptor
def initialize(recipient)
@recipient = recipient
end
def delivering_email(mail)
mail.smtp_envelope_to = @recipient
end
end
Mail.register_interceptor CanonicalEnvelopeRecipientInterceptor.new('[email protected]') |
Closing in favor of using an interceptor to alter outgoing emails. That can be used with any delivery method, not just SMTP. |
Use the OverrideRecipientSMTP delivery method when you don't want your program
to accidentally send emails to addresses other than the overridden recipient
which you configure.
An example use case is in your web app's staging environment, your development
team will receive all staging emails without accidentally emailing users with
active email addresses in the database.