I have a rails application running in a staging-environment, which is an accurate copy of the production. I would like to be able to send mails with ActionMailer, to test that it all works as it should, but to prevent any mistakes, I would very much like to be able to restrict the mailer from sending out to any addresses that are not on my own domain.
It doesn't seem that ActionMailer supports this from the get go, but is there a plugin or perhaps a patch of some sort, that could do this?
I am doing following with success:
module FilteredMailer
def self.included(base)
base.class_eval do
alias_method :create_mail_orig, :create_mail
def create_mail
recipients(filter_out_recipients(recipients))
create_mail_orig
end
end
end
private
def filter_out_recipients(recipients)
...
end
end
You need to include this module in all your mailers. This works in Rails 2.3.8, I don't know if it works in Rails 3.
Take a look at the sanitize_email gem - it's a fine solution for this.
It doesn't let you specify a domain, but it does allow you to restrict email sending to a specific list of recipients which will prevent any emails going to unintended recipients.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With