Git Product home page Git Product logo

mail_safe's Introduction

Build Status Coverage Status Code Climate Inline docs Gem Version

mail_safe

Mail safe provides a safety net while you're developing an application that uses ActionMailer. It keeps emails from escaping into the wild.

Once you've installed and configured this gem, you can rest assure that your app won't send emails to external email addresses. Instead, emails that would normally be delivered to external addresses will be sent to an address of your choosing, and the body of the email will be appended with a note stating where the email was originally intended to go.

Download

Github: http://github.com/myronmarston/mail_safe

Gem: gem install mail_safe

Installation

Load the gem in the appropriate environments using Rails' 3.2+ gem support. For example, I'm loading this in Gemfile as:

gem "mail_safe", group: [:development, :staging]

IMPORTANT: Be sure not to load this in your production environment, otherwise, your emails won't be sent to the proper recipients. In your test environment, you probably won't want this either. Rails ensures that no emails are ever sent in the test environment, and tests that check outbound email recipients may fail.

Configuration

In many cases, no configuration is necessary. If you have git installed, and you've registered your email address with it (check with "git config user.email" in your shell), mail safe will use this. All emails will be sent to this address.

Otherwise, you can configure mail safe's behavior. Create a file at config/initializers/mail_safe.rb, similar to the following:

  if defined?(MailSafe::Config)
    MailSafe::Config.internal_address_definition = /.*@my-domain\.com/i
    MailSafe::Config.replacement_address = '[email protected]'
  end

The internal address definition determines which addresses will be ignored (i.e. sent normally) and which will be replaced. Email being sent to internal addresses will be sent normally; all other email addresses will be replaced by the replacement address.

These settings can also take procs if you need something more flexible:

  if defined?(MailSafe::Config)
    MailSafe::Config.internal_address_definition = lambda { |address|
      address =~ /.*@domain1\.com/i ||
      address =~ /.*@domain2\.com/i ||
      address == '[email protected]'
    }

    # Useful if your mail server allows + dynamic email addresses like gmail.
    MailSafe::Config.replacement_address = lambda { |address| "my-address+#{address.gsub(/[\w\-.]/, '_')}@gmail.com" }
  end

When mail safe replaces an email address, it appends a notice to the bottom of the email body, such as:

  **************************************************
  This email originally had different recipients,
  but MailSafe has prevented it from being sent to them.

  The original recipients were:
  - to:
   - [email protected]
   - [email protected]
  - cc:
   - [email protected]

  **************************************************

Version Compatibility and Continuous Integration

Tested with Travis using Ruby 1.9, 2.0 and 2.1 against actionmailer 3.2, 4.0 and 4.1. Build Status

To locally run tests do:

appraisal rake test
```

## Changelog for 0.3.2 version

* Updated to manage the gem using bundler.
* Updated to run tests with RSpec 3.
* Updated to support actionmailer >= 3.2 (support for older versions was removed to simplify code).
* Changed ginger in favor of appraisal to test the gem against different versions of actionmailer.
* Added support for continuous integrations with Travis (can be locally emulated with wwtd).
* Fixed https://github.com/myronmarston/mail_safe/issues/7
* Fixed https://github.com/myronmarston/mail_safe/issues/3
* Updated source code page with some fancy badges.

## Copyright

Copyright (c) 2009-2010 Myron Marston, Kashless.org.

Copyright (c) 2014, Watu

See LICENSE for details.

mail_safe's People

Contributors

jjconti avatar myronmarston avatar pupeno avatar codemonkeysteve avatar davekaro avatar

Stargazers

Michael Hagar avatar Thomas Klemm avatar Chris Hough avatar Michael Telford avatar Tim Krins avatar Juri Hahn avatar Christopher Ritsen avatar ibraheem4 avatar Matt Bauer avatar Wajid Kagzi avatar Akhil Dave avatar Evgenii Burdaev avatar Mac Młynarczyk avatar Angus H. avatar Nate R avatar Sebastian Cohnen avatar John Backus avatar Yanming Deng avatar Masahiro Kyuden avatar Mark Tran avatar Donovan Dikaio avatar bhertach avatar Pablo Martí avatar Fernando Juarez avatar raul avatar Scott Shillcock avatar Alex avatar Mathieu Allaire avatar Ankur Goel avatar  avatar Tarek Koudsi avatar Alex Willemsma avatar Elikem Adadevoh avatar Yuki Nishijima avatar Alexandru Leasenco avatar Ryan Wood avatar Adrian Teh avatar Sasha Gerrand avatar Michael Orr avatar Maher Saif avatar Steven Hansen avatar Jules Omlor avatar Anthony Scalisi avatar 大野 avatar Stephen Thomas avatar Ravi avatar  avatar brysj avatar lidashuang avatar  avatar Ty Cohen avatar Alexander Zaytsev avatar Zhiping Yang avatar ash bhoopathy avatar Blake Jakopovic avatar Prashanth Ramanath avatar Jake Mauer avatar Allan Lloyds avatar Jeff avatar Maksim Soltan avatar Ed Shadi avatar Jacques Crocker avatar Charles Swanberg avatar  avatar Matt Lohier avatar Jeff Federman avatar  avatar Alexey Artamonov avatar Joel Van Horn avatar Venu Keesari avatar Joseph Weissman avatar  avatar Buts Johan avatar Mike Pepper avatar Jason Weathered avatar Andrew Hite avatar Eric Milford avatar Steve Hodgkiss avatar Peter P. Gengler avatar Nugroho Herucahyono avatar  avatar Marston A. avatar Jesse House avatar  avatar Kevin Burkhardt avatar Andy Wang avatar Gus Becciu avatar Kyle Bragger avatar William T. Nelson avatar Brian Racer avatar Paul Covell avatar  avatar Chris Irish avatar Flávio Granero avatar Patrick Aljord avatar Stefan Botzenhart avatar Benjamin Quorning avatar Oleh Khomei avatar Peter Boling avatar Michael MacDonald avatar

Watchers

James Cloos avatar Ala'a Mohammad avatar Anthony Scalisi avatar  avatar  avatar

mail_safe's Issues

Globally disable without config?

The mere presence of this gem preventing emails from going out seems like a dangerous approach. Why require configuration to be both in the Gemfile and the initializer?

When using a weird address mail_safe crashes

I'm creating users with weird email addresses, like <script>alert("XSS!")</script>@<script>alert("XSS!")</script>.com, just to help find cases where I'm open to XSS in the app. When sending an email to one of those addresses mail_safe crashes with this backtrace:

undefined method `each' for #<String:0x007fddcd3575e8>
/Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/mail_safe-0.3.1/lib/mail_safe/address_replacer.rb:14:in `block in replace_external_addresses'
/Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/mail_safe-0.3.1/lib/mail_safe/address_replacer.rb:9:in `each'
/Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/mail_safe-0.3.1/lib/mail_safe/address_replacer.rb:9:in `replace_external_addresses'
/Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/mail_safe-0.3.1/lib/mail_safe/rails3_hook.rb:6:in `delivering_email'
/Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/mail-2.3.0/lib/mail/mail.rb:230:in `block in inform_interceptors'
/Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/mail-2.3.0/lib/mail/mail.rb:229:in `each'
/Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/mail-2.3.0/lib/mail/mail.rb:229:in `inform_interceptors'
/Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/mail-2.3.0/lib/mail/message.rb:218:in `inform_interceptors'
/Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/mail-2.3.0/lib/mail/message.rb:228:in `deliver'
/Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/devise-1.4.7/lib/devise/models/confirmable.rb:50:in `send_confirmation_instructions'

Apparently mail.send(address_type) doesn't return an array but just a string.

Sanity check please - Rails console

I love the mail safe gem and its a great tool, but can someone else please check to see whether it protects email sent from the console.

It seems to protect when running as a server but not from a console.

Preserve address names

Addresses of the form "Name user@domain" are converted to "user@domain", even when not replacing the address. Need to preserve the address name, whether or not user/domain are replaced.

(note: this issue is just a reminder - I'll fix this, if you don't get around to fixing it first).

Better description on the replacement_address error

This threw one of our new developers off, and I spent half an hour working out why this was working for me and not for her.. It would be great to say "Set your git user email or ensure replacement_address is a string or proc" :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.