0.06
No commit activity in last 3 years
No release in over 3 years
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. Useful for testing and staging environments.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

safety_mailer¶ ↑

Restrict email sent by your application to only approved domains or accounts.

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.

This is useful for testing or staging environments where you want to be certain email to real customers doesn’t escape the lab.

Layered on the Mail gem, so Rails >= 3.0 applications can use safety_mailer.

Rails >= 3.0¶ ↑

Add the gem to your Gemfile, specifying groups (probably not production) to include it in.

gem "safety_mailer", :group => :development

Don’t forget to bundle install to install

In your environment file config/environments/development.rb configure it, and some regular expressions.

config.action_mailer.delivery_method = :safety_mailer
config.action_mailer.safety_mailer_settings = {
  allowed_matchers: [ /mydomain.com/, /mytestacct@gmail.com/, /super_secret_test/ ],
  delivery_method: :smtp,
  delivery_method_settings: {
    :address => "smtp.mydomain.com",
    :port => 25,
    :domain => "mydomain.com",
    :authentication => :plain,
    :user_name => "mydomain_mailer@mydomain.com",
    :password => "password"
  }
}

… 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.

Non-Rails¶ ↑

Any user of the Mail gem can configure safety_mailer:

require "safety_mailer"
Mail.defaults do
  delivery_method SafetyMailer::Carrier, {
    ... same settings as above
  }
end

Non-Mail¶ ↑

If you’re not using the Mail gem (or use it sometimes but want to use the same logic / configuration in other contexts), you can filter directly:

filtered_array = SafetyMailer::Carrier.new(ActionMailer::Base.safety_mailer_settings).filter(unfiltered_email_addresses)

License¶ ↑

safety_mailer is released under the MIT license: