We want to test email functionality on our staging server, but we don’t want to accidentally email customers.
So, I’d like emails sent to “anything@corporation.com” to work, but emails sent to “anything@customer.com” to be suppressed.
I could just go into all of my controllers and put in code that only fires the “deliver” method if the email contains our domain or the environment is prod. But, that seems kinda kludgey. I’d like to do it app wide.
Applications that use the Mail gem (including rails >= 3.0 projects) can use the safety_mailer gem. Specify a domain (or set of domains, or magic word in email address) email is allowed to go to, and email to all other domains is silently dropped.
https://github.com/cluesque/safety_mailer
Add the gem to your Gemfile, specifying groups (probably not production) to include it in.
Don’t forget to bundle install to install
In your environment file config/environments/development.rb configure it, and some regular expressions.
… and now, email to anyone@mydomain.com, mytestacct@gmail.com, bob+super_secret_test@yahoo.com all get sent
and email to other recipients (like the real users in the production database you copied to a test server) is suppressed.