When developing a web application that sends email, sometimes you want to be careful about who it can send to. Rails makes it easy to send no email, but you may want messages to go to yourself and colleagues, without accidentally sending to your entire customer base.
Introducing safety_mailer. It allows you to specify a set of domains or accounts or magic words that will allow some email to get through, while silently discarding the rest.
We use it in our rails application (it will work with 3.0 or newer), but it should also work with any project using the Mail gem.
Setup with Rails >= 3.0
Add the gem to your
Gemfile, specifying groups (probably not production) to include it in.
gem "safety_mailer", :group => :development
bundle install to install
In your environment files
config/environments/staging.rb) configure it, and some regular expressions.
config.action_mailer.delivery_method = :safety_mailer SafetyMailer::Config.allowed_matchers = [ /mydomain.com/, /email@example.com/, /super_secret_test/ ]
... and now, email to firstname.lastname@example.org, email@example.com, firstname.lastname@example.org all get sent and email to other recipients (like the real users in the production database you copied to a test server) is suppressed.
Any user of the Mail gem can configure safety_mailer:
require "safety_mailer" Mail.defaults do delivery_method SafetyMailer::Carrier end SafetyMailer::Config.allowed_matchers = [ /mydomain.com/, /email@example.com/, /super_secret_test/ ]