safety_mailer 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +41 -0
- data/lib/safety_mailer/railtie.rb +7 -0
- data/lib/safety_mailer/safety_mailer.rb +33 -0
- data/lib/safety_mailer.rb +2 -0
- metadata +68 -0
data/README.rdoc
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
== safety_mailer
|
2
|
+
|
3
|
+
Restrict email sent by your application to only approved domains or accounts.
|
4
|
+
|
5
|
+
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.
|
6
|
+
|
7
|
+
This is useful for testing or staging environments where you want to be certain email to real customers doesn't escape the lab.
|
8
|
+
|
9
|
+
Layered on the Mail gem, so Rails >= 3.0 applications can use safety_mailer.
|
10
|
+
|
11
|
+
== Rails >= 3.0
|
12
|
+
|
13
|
+
Add the gem to your +Gemfile+, specifying groups (probably not production) to include it in.
|
14
|
+
|
15
|
+
gem "safety_mailer", :group => :development
|
16
|
+
|
17
|
+
Don't forget to <tt>bundle install</tt> to install
|
18
|
+
|
19
|
+
In your environment file <tt>config/environments/development.rb</tt> configure it, and some regular expressions.
|
20
|
+
|
21
|
+
config.action_mailer.delivery_method = :safety_mailer
|
22
|
+
SafetyMailer::Config.allowed_matchers = [ /mydomain.com/, /mytestacct@gmail.com/, /super_secret_test/ ]
|
23
|
+
|
24
|
+
... and now, email to anyone@mydomain.com, mytestacct@gmail.com, bob+super_secret_test@yahoo.com all get sent
|
25
|
+
and email to other recipients (like the real users in the production database you copied to a test server) is suppressed.
|
26
|
+
|
27
|
+
== Non-Rails
|
28
|
+
|
29
|
+
Any user of the Mail gem can configure safety_mailer:
|
30
|
+
|
31
|
+
require "safety_mailer"
|
32
|
+
Mail.defaults do
|
33
|
+
delivery_method SafetyMailer::Carrier
|
34
|
+
end
|
35
|
+
SafetyMailer::Config.allowed_matchers = [ /mydomain.com/, /mytestacct@gmail.com/, /super_secret_test/ ]
|
36
|
+
|
37
|
+
== License
|
38
|
+
|
39
|
+
safety_mailer is released under the MIT license:
|
40
|
+
|
41
|
+
* http://www.opensource.org/licenses/MIT
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module SafetyMailer
|
2
|
+
class Config
|
3
|
+
@@allowed_matchers = []
|
4
|
+
cattr_accessor :allowed_matchers
|
5
|
+
@@delivery_method = :smtp
|
6
|
+
cattr_accessor :delivery_method
|
7
|
+
end
|
8
|
+
class Carrier
|
9
|
+
attr_accessor :params
|
10
|
+
def initialize(params = {})
|
11
|
+
self.params = params
|
12
|
+
end
|
13
|
+
def log(msg)
|
14
|
+
Rails.logger.warn(msg) if defined?(Rails)
|
15
|
+
end
|
16
|
+
def deliver!(mail)
|
17
|
+
mail.to = mail.to.reject do |recipient|
|
18
|
+
if SafetyMailer::Config.allowed_matchers.any?{ |m| recipient =~ m }
|
19
|
+
false
|
20
|
+
else
|
21
|
+
log "*** safety_mailer suppressing mail to #{recipient}"
|
22
|
+
true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
if mail.to.nil? || mail.to.empty?
|
26
|
+
log "*** safety_mailer - no recipients left ... suppressing delivery altogether"
|
27
|
+
else
|
28
|
+
log "*** safety_mailer allowing delivery to #{mail.to}"
|
29
|
+
Mail::Configuration.instance.lookup_delivery_method(SafetyMailer::Config.delivery_method).deliver!(mail)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: safety_mailer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Bill Kirtley
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-02-08 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: 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.
|
22
|
+
email: bill.kirtley@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- lib/safety_mailer/railtie.rb
|
31
|
+
- lib/safety_mailer/safety_mailer.rb
|
32
|
+
- lib/safety_mailer.rb
|
33
|
+
- README.rdoc
|
34
|
+
homepage: http://github.com/cluesque/safety_opener
|
35
|
+
licenses: []
|
36
|
+
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
hash: 3
|
48
|
+
segments:
|
49
|
+
- 0
|
50
|
+
version: "0"
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.8.15
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: Restrict email sent by your application to only approved domains or accounts.
|
67
|
+
test_files: []
|
68
|
+
|