Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

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

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 safety_mailer.gemspec


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: [ /, /, /super_secret_test/ ],
  delivery_method: :smtp,
  delivery_method_settings: {
    :address => "",
    :port => 25,
    :domain => "",
    :authentication => :plain,
    :user_name => "",
    :password => "password"

… and now, email to,, 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, {
    ... same settings as above


safety_mailer is released under the MIT license:

Something went wrong with that request. Please try again.