mail_magnet 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +18 -4
- data/VERSION +1 -1
- data/lib/mail_magnet/tmail_ext.rb +2 -1
- data/mail_magnet.gemspec +7 -6
- data/spec/app_root/app/models/mailer.rb +8 -0
- data/spec/app_root/app/views/mailer/html_letter.erb +1 -0
- data/spec/mail_magnet_spec.rb +20 -0
- metadata +8 -7
data/README.rdoc
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
= Mail Magnet
|
2
2
|
|
3
|
-
Mail Magnet allows you to override e-mail recipients in ActionMailer
|
4
|
-
|
5
|
-
http://gem-session.com/2010/06/overriding-e-mail-recipients-in-actionmailer
|
3
|
+
Mail Magnet allows you to override e-mail recipients in ActionMailer so all mails go to a given address.
|
4
|
+
This is useful for staging environments where you want to test production-like mail delivery without sending e-mails to real users.
|
6
5
|
|
7
6
|
== Installation
|
8
7
|
|
9
8
|
Install the gem with
|
9
|
+
|
10
10
|
sudo gem install mail_magnet
|
11
11
|
|
12
|
-
|
12
|
+
In the environment for which you'd like to override mail recipients:
|
13
|
+
|
14
|
+
config.gem 'mail_magnet'
|
15
|
+
config.after_initialize { ActionMailer::Base.override_recipients = 'overridden@example.com' }
|
16
|
+
|
17
|
+
Now all e-mail sent by your ActionMailers goes to 'overridden@example.com' (including CC and BCC recipients).
|
18
|
+
The original recipients will be quoted inside the mail body, like this:
|
19
|
+
|
20
|
+
- - - Original recipients - - -
|
21
|
+
To: original.to@example.com
|
22
|
+
Cc: original.cc@example.com
|
23
|
+
Bcc: original.bcc@example.com
|
24
|
+
- - - - - - - - - - - - - - - -
|
25
|
+
|
26
|
+
Original e-mail body goes here.
|
13
27
|
|
14
28
|
== Rails 3 compatibility
|
15
29
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -15,7 +15,8 @@ TMail::Mail.class_eval do
|
|
15
15
|
end
|
16
16
|
parts << "---------------------------"
|
17
17
|
|
18
|
-
self.
|
18
|
+
line_break = self.content_type =~ /(html)/ ? "<br />" : "\n"
|
19
|
+
self.body = parts.join(line_break) + line_break*2 + self.body
|
19
20
|
end
|
20
21
|
|
21
22
|
def override(method, recipients)
|
data/mail_magnet.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mail_magnet}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Arne Hartherz"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-09-16}
|
13
13
|
s.description = %q{Override ActionMailer recipients so all mails go to a given address}
|
14
14
|
s.email = %q{github@makandra.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
"mail_magnet.gemspec",
|
28
28
|
"spec/app_root/app/controllers/application_controller.rb",
|
29
29
|
"spec/app_root/app/models/mailer.rb",
|
30
|
+
"spec/app_root/app/views/mailer/html_letter.erb",
|
30
31
|
"spec/app_root/app/views/mailer/letter.erb",
|
31
32
|
"spec/app_root/config/boot.rb",
|
32
33
|
"spec/app_root/config/database.yml",
|
@@ -51,17 +52,17 @@ Gem::Specification.new do |s|
|
|
51
52
|
s.rubygems_version = %q{1.3.6}
|
52
53
|
s.summary = %q{Override ActionMailer recipients so all mails go to a given address}
|
53
54
|
s.test_files = [
|
54
|
-
"spec/app_root/
|
55
|
+
"spec/app_root/app/controllers/application_controller.rb",
|
56
|
+
"spec/app_root/app/models/mailer.rb",
|
57
|
+
"spec/app_root/config/boot.rb",
|
55
58
|
"spec/app_root/config/environment.rb",
|
56
|
-
"spec/app_root/config/routes.rb",
|
57
59
|
"spec/app_root/config/environments/in_memory.rb",
|
58
60
|
"spec/app_root/config/environments/mysql.rb",
|
59
61
|
"spec/app_root/config/environments/postgresql.rb",
|
60
62
|
"spec/app_root/config/environments/sqlite.rb",
|
61
63
|
"spec/app_root/config/environments/sqlite3.rb",
|
64
|
+
"spec/app_root/config/routes.rb",
|
62
65
|
"spec/app_root/lib/console_with_fixtures.rb",
|
63
|
-
"spec/app_root/app/controllers/application_controller.rb",
|
64
|
-
"spec/app_root/app/models/mailer.rb",
|
65
66
|
"spec/spec_helper.rb",
|
66
67
|
"spec/mail_magnet_spec.rb"
|
67
68
|
]
|
@@ -7,4 +7,12 @@ class Mailer < ActionMailer::Base
|
|
7
7
|
subject 'Hello Universe!'
|
8
8
|
end
|
9
9
|
|
10
|
+
def html_letter
|
11
|
+
recipients 'original.to@example.com'
|
12
|
+
cc 'original.cc@example.com'
|
13
|
+
bcc 'original.bcc@example.com'
|
14
|
+
subject 'Hello Universe!'
|
15
|
+
content_type "text/html"
|
16
|
+
end
|
17
|
+
|
10
18
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
HTMLello!
|
data/spec/mail_magnet_spec.rb
CHANGED
@@ -45,4 +45,24 @@ describe 'mail_magnet' do
|
|
45
45
|
ActionMailer::Base.deliveries.last.subject.should == 'Hello Universe!'
|
46
46
|
end
|
47
47
|
|
48
|
+
it 'should detect the content_type correctly' do
|
49
|
+
ActionMailer::Base.override_recipients = 'overridden.to@example.com'
|
50
|
+
Mailer.deliver_letter
|
51
|
+
ActionMailer::Base.deliveries.last.content_type.should == "text/plain"
|
52
|
+
Mailer.deliver_html_letter
|
53
|
+
ActionMailer::Base.deliveries.last.content_type.should include("text/html") # content_type sometimes ends with "; charset=utf-8"
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should use "\n" for line breaks in plain text emails' do
|
57
|
+
ActionMailer::Base.override_recipients = 'overridden.to@example.com'
|
58
|
+
Mailer.deliver_letter
|
59
|
+
ActionMailer::Base.deliveries.last.body.should include("To: original.to@example.com\n")
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should use "<br />" for line breaks in HTML emails' do
|
63
|
+
ActionMailer::Base.override_recipients = 'overridden.to@example.com'
|
64
|
+
Mailer.deliver_html_letter
|
65
|
+
ActionMailer::Base.deliveries.last.body.should include('To: original.to@example.com<br />')
|
66
|
+
end
|
67
|
+
|
48
68
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Arne Hartherz
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-09-16 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- mail_magnet.gemspec
|
39
39
|
- spec/app_root/app/controllers/application_controller.rb
|
40
40
|
- spec/app_root/app/models/mailer.rb
|
41
|
+
- spec/app_root/app/views/mailer/html_letter.erb
|
41
42
|
- spec/app_root/app/views/mailer/letter.erb
|
42
43
|
- spec/app_root/config/boot.rb
|
43
44
|
- spec/app_root/config/database.yml
|
@@ -86,16 +87,16 @@ signing_key:
|
|
86
87
|
specification_version: 3
|
87
88
|
summary: Override ActionMailer recipients so all mails go to a given address
|
88
89
|
test_files:
|
90
|
+
- spec/app_root/app/controllers/application_controller.rb
|
91
|
+
- spec/app_root/app/models/mailer.rb
|
89
92
|
- spec/app_root/config/boot.rb
|
90
93
|
- spec/app_root/config/environment.rb
|
91
|
-
- spec/app_root/config/routes.rb
|
92
94
|
- spec/app_root/config/environments/in_memory.rb
|
93
95
|
- spec/app_root/config/environments/mysql.rb
|
94
96
|
- spec/app_root/config/environments/postgresql.rb
|
95
97
|
- spec/app_root/config/environments/sqlite.rb
|
96
98
|
- spec/app_root/config/environments/sqlite3.rb
|
99
|
+
- spec/app_root/config/routes.rb
|
97
100
|
- spec/app_root/lib/console_with_fixtures.rb
|
98
|
-
- spec/app_root/app/controllers/application_controller.rb
|
99
|
-
- spec/app_root/app/models/mailer.rb
|
100
101
|
- spec/spec_helper.rb
|
101
102
|
- spec/mail_magnet_spec.rb
|