actionmailer 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionmailer might be problematic. Click here for more details.
- data/CHANGELOG +16 -0
- data/lib/action_mailer.rb +0 -1
- data/lib/action_mailer/base.rb +57 -16
- data/rakefile +14 -6
- data/test/mail_service_test.rb +48 -9
- metadata +3 -3
data/CHANGELOG
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
*0.4* (5)
|
2
|
+
|
3
|
+
* Consolidated the server configuration options into Base#server_settings= and expanded that with controls for authentication and more [Marten]
|
4
|
+
NOTE: This is an API change that could potentially break your application if you used the old application form. Please do change!
|
5
|
+
|
6
|
+
* Added Base#deliveries as an accessor for an array of emails sent out through that ActionMailer class when using the :test delivery option. [bitsweat]
|
7
|
+
|
8
|
+
* Added Base#perform_deliveries= which can be set to false to turn off the actual delivery of the email through smtp or sendmail.
|
9
|
+
This is especially useful for functional testing that shouldn't send off real emails, but still trigger delivery_* methods.
|
10
|
+
|
11
|
+
* Added option to specify delivery method with Base#delivery_method=. Default is :smtp and :sendmail is currently the only other option.
|
12
|
+
Sendmail is assumed to be present at "/usr/sbin/sendmail" if that option is used. [Kent Sibilev]
|
13
|
+
|
14
|
+
* Dropped "include TMail" as it added to much baggage into the default namespace (like Version) [Chad Fowler]
|
15
|
+
|
16
|
+
|
1
17
|
*0.3*
|
2
18
|
|
3
19
|
* First release
|
data/lib/action_mailer.rb
CHANGED
data/lib/action_mailer/base.rb
CHANGED
@@ -34,18 +34,44 @@ module ActionMailer #:nodoc:
|
|
34
34
|
# Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers.
|
35
35
|
cattr_accessor :logger
|
36
36
|
|
37
|
-
# Allows
|
38
|
-
|
39
|
-
|
37
|
+
# Allows detailed configuration of the server:
|
38
|
+
# * <tt>:address</tt> Allows you to use a remote mail server. Just change it away from it's default "localhost" setting.
|
39
|
+
# * <tt>:port</tt> On the off change that your mail server doesn't run on port 25, you can change it.
|
40
|
+
# * <tt>:domain</tt> If you need to specify a HELO domain, you can do it here.
|
41
|
+
# * <tt>:user_name</tt> If your mail server requires authentication, set the username and password in these two settings.
|
42
|
+
# * <tt>:password</tt> If your mail server requires authentication, set the username and password in these two settings.
|
43
|
+
# * <tt>:authentication</tt> If your mail server requires authentication, you need to specify the authentication type here.
|
44
|
+
# This is a symbol and one of :plain, :login, :cram_md5
|
45
|
+
@@server_settings = {
|
46
|
+
:address => "localhost",
|
47
|
+
:port => 25,
|
48
|
+
:domain => 'localhost.localdomain',
|
49
|
+
:user_name => nil,
|
50
|
+
:password => nil,
|
51
|
+
:authentication => nil
|
52
|
+
}
|
53
|
+
cattr_accessor :server_settings
|
40
54
|
|
41
|
-
# On the off change that your mail server doesn't run on port 25, you can change it.
|
42
|
-
@@mail_server_port = 25
|
43
|
-
cattr_accessor :mail_server_port
|
44
55
|
|
45
56
|
# Whether or not errors should be raised if the email fails to be delivered
|
46
57
|
@@raise_delivery_errors = true
|
47
58
|
cattr_accessor :raise_delivery_errors
|
48
59
|
|
60
|
+
# Defines a delivery method. Possible values are :smtp (default), :sendmail, and :test.
|
61
|
+
# Sendmail is assumed to be present at "/usr/sbin/sendmail".
|
62
|
+
@@delivery_method = :smtp
|
63
|
+
cattr_accessor :delivery_method
|
64
|
+
|
65
|
+
# Determines whether deliver_* methods are actually carried out. By default they are,
|
66
|
+
# but this can be turned off to help functional testing.
|
67
|
+
@@perform_deliveries = true
|
68
|
+
cattr_accessor :perform_deliveries
|
69
|
+
|
70
|
+
# Keeps an array of all the emails sent out through the Action Mailer with delivery_method :test. Most useful
|
71
|
+
# for unit and functional testing.
|
72
|
+
@@deliveries = []
|
73
|
+
cattr_accessor :deliveries
|
74
|
+
|
49
75
|
attr_accessor :recipients, :subject, :body, :from, :sent_on, :bcc, :cc
|
50
76
|
|
51
77
|
class << self
|
@@ -62,26 +88,41 @@ module ActionMailer #:nodoc:
|
|
62
88
|
end
|
63
89
|
end
|
64
90
|
|
65
|
-
def mail(to, subject, body, from, timestamp = nil)#:nodoc:
|
91
|
+
def mail(to, subject, body, from, timestamp = nil) #:nodoc:
|
66
92
|
deliver(create(to, subject, body, from, timestamp))
|
67
93
|
end
|
68
|
-
|
69
|
-
def create(to, subject, body, from, timestamp = nil)#:nodoc:
|
70
|
-
m = Mail.new
|
94
|
+
|
95
|
+
def create(to, subject, body, from, timestamp = nil) #:nodoc:
|
96
|
+
m = TMail::Mail.new
|
71
97
|
m.to, m.subject, m.body, m.from = to, subject, body, from
|
72
98
|
m.date = timestamp.respond_to?("to_time") ? timestamp.to_time : (timestamp || Time.now)
|
73
99
|
return m
|
74
100
|
end
|
75
101
|
|
76
|
-
def deliver(mail)#:nodoc:
|
102
|
+
def deliver(mail) #:nodoc:
|
77
103
|
logger.info "Sent mail:\n #{mail.encoded}" unless logger.nil?
|
104
|
+
send("perform_delivery_#{delivery_method}", mail) if perform_deliveries
|
105
|
+
end
|
78
106
|
|
79
|
-
|
80
|
-
|
107
|
+
private
|
108
|
+
def perform_delivery_smtp(mail)
|
109
|
+
Net::SMTP.start(server_settings[:address], server_settings[:port], server_settings[:domain],
|
110
|
+
server_settings[:user_name], server_settings[:password], server_settings[:authentication]) do |smtp|
|
111
|
+
smtp.sendmail(mail.encoded, mail.from_address, mail.destinations)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def perform_delivery_sendmail(mail)
|
116
|
+
IO.popen("/usr/sbin/sendmail -i -t","w+") do |sm|
|
117
|
+
sm.print(mail.encoded)
|
118
|
+
sm.flush
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def perform_delivery_test(mail)
|
123
|
+
deliveries << mail
|
81
124
|
end
|
82
|
-
end
|
83
125
|
|
84
|
-
private
|
85
126
|
def create_from_action(method_name, *parameters)
|
86
127
|
mailer = new
|
87
128
|
mailer.body = {}
|
@@ -108,4 +149,4 @@ module ActionMailer #:nodoc:
|
|
108
149
|
end
|
109
150
|
end
|
110
151
|
end
|
111
|
-
end
|
152
|
+
end
|
data/rakefile
CHANGED
@@ -6,7 +6,10 @@ require 'rake/packagetask'
|
|
6
6
|
require 'rake/gempackagetask'
|
7
7
|
require 'rake/contrib/rubyforgepublisher'
|
8
8
|
|
9
|
-
|
9
|
+
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
|
10
|
+
PKG_NAME = 'actionmailer'
|
11
|
+
PKG_VERSION = '0.4.0' + PKG_BUILD
|
12
|
+
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
10
13
|
|
11
14
|
desc "Default Task"
|
12
15
|
task :default => [ :test ]
|
@@ -37,7 +40,7 @@ Rake::RDocTask.new { |rdoc|
|
|
37
40
|
|
38
41
|
spec = Gem::Specification.new do |s|
|
39
42
|
s.platform = Gem::Platform::RUBY
|
40
|
-
s.name =
|
43
|
+
s.name = PKG_NAME
|
41
44
|
s.summary = "Service layer for easy email delivery and testing."
|
42
45
|
s.description = %q{Makes it trivial to test and deliver emails sent from a single service layer.}
|
43
46
|
s.version = PKG_VERSION
|
@@ -47,7 +50,7 @@ spec = Gem::Specification.new do |s|
|
|
47
50
|
s.rubyforge_project = "actionmailer"
|
48
51
|
s.homepage = "http://actionmailer.rubyonrails.org"
|
49
52
|
|
50
|
-
s.add_dependency('actionpack', '>= 0.9.
|
53
|
+
s.add_dependency('actionpack', '>= 0.9.5')
|
51
54
|
|
52
55
|
s.has_rdoc = true
|
53
56
|
s.requirements << 'none'
|
@@ -66,6 +69,11 @@ Rake::GemPackageTask.new(spec) do |p|
|
|
66
69
|
end
|
67
70
|
|
68
71
|
|
72
|
+
# Publish beta gem
|
73
|
+
desc "Publish the API documentation"
|
74
|
+
task :pgem => [:package] do
|
75
|
+
Rake::SshFilePublisher.new("davidhh@one.textdrive.com", "domains/rubyonrails.org/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
|
76
|
+
end
|
69
77
|
|
70
78
|
# Publish documentation
|
71
79
|
desc "Publish the API documentation"
|
@@ -83,10 +91,10 @@ desc "Count lines in the main rake file"
|
|
83
91
|
task :lines do
|
84
92
|
lines = 0
|
85
93
|
codelines = 0
|
86
|
-
Dir.foreach("lib/
|
94
|
+
Dir.foreach("lib/action_mailer") { |file_name|
|
87
95
|
next unless file_name =~ /.*rb/
|
88
96
|
|
89
|
-
f = File.open("lib/
|
97
|
+
f = File.open("lib/action_mailer/" + file_name)
|
90
98
|
|
91
99
|
while line = f.gets
|
92
100
|
lines += 1
|
@@ -96,4 +104,4 @@ task :lines do
|
|
96
104
|
end
|
97
105
|
}
|
98
106
|
puts "Lines #{lines}, LOC #{codelines}"
|
99
|
-
end
|
107
|
+
end
|
data/test/mail_service_test.rb
CHANGED
@@ -24,30 +24,69 @@ end
|
|
24
24
|
TestMailer.template_root = File.dirname(__FILE__) + "/fixtures"
|
25
25
|
|
26
26
|
class ActionMailerTest < Test::Unit::TestCase
|
27
|
+
def setup
|
28
|
+
ActionMailer::Base.delivery_method = :test
|
29
|
+
ActionMailer::Base.perform_deliveries = true
|
30
|
+
ActionMailer::Base.deliveries = []
|
31
|
+
|
32
|
+
@recipient = 'test@localhost'
|
33
|
+
end
|
34
|
+
|
27
35
|
def test_signed_up
|
28
36
|
expected = TMail::Mail.new
|
29
|
-
expected.to =
|
30
|
-
expected.subject = "[Signed up] Welcome
|
31
|
-
expected.body = "Hello there, \n\nMr.
|
37
|
+
expected.to = @recipient
|
38
|
+
expected.subject = "[Signed up] Welcome #{@recipient}"
|
39
|
+
expected.body = "Hello there, \n\nMr. #{@recipient}"
|
32
40
|
expected.from = "system@loudthinking.com"
|
33
41
|
expected.date = Time.local(2004, 12, 12)
|
34
42
|
|
35
|
-
|
43
|
+
created = nil
|
44
|
+
assert_nothing_raised { created = TestMailer.create_signed_up(@recipient) }
|
45
|
+
assert_not_nil created
|
46
|
+
assert_equal expected.encoded, created.encoded
|
47
|
+
|
48
|
+
assert_nothing_raised { TestMailer.deliver_signed_up(@recipient) }
|
49
|
+
assert_not_nil ActionMailer::Base.deliveries.first
|
50
|
+
assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
|
36
51
|
end
|
37
52
|
|
38
53
|
def test_cancelled_account
|
39
54
|
expected = TMail::Mail.new
|
40
|
-
expected.to =
|
41
|
-
expected.subject = "[Cancelled] Goodbye
|
42
|
-
expected.body = "Goodbye, Mr.
|
55
|
+
expected.to = @recipient
|
56
|
+
expected.subject = "[Cancelled] Goodbye #{@recipient}"
|
57
|
+
expected.body = "Goodbye, Mr. #{@recipient}"
|
43
58
|
expected.from = "system@loudthinking.com"
|
44
59
|
expected.date = Time.local(2004, 12, 12)
|
45
60
|
|
46
|
-
|
61
|
+
created = nil
|
62
|
+
assert_nothing_raised { created = TestMailer.create_cancelled_account(@recipient) }
|
63
|
+
assert_not_nil created
|
64
|
+
assert_equal expected.encoded, created.encoded
|
65
|
+
|
66
|
+
assert_nothing_raised { TestMailer.deliver_cancelled_account(@recipient) }
|
67
|
+
assert_not_nil ActionMailer::Base.deliveries.first
|
68
|
+
assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
|
47
69
|
end
|
48
70
|
|
49
71
|
def test_instances_are_nil
|
50
72
|
assert_nil ActionMailer::Base.new
|
51
73
|
assert_nil TestMailer.new
|
52
74
|
end
|
53
|
-
|
75
|
+
|
76
|
+
def test_deliveries_array
|
77
|
+
assert_not_nil ActionMailer::Base.deliveries
|
78
|
+
assert_equal 0, ActionMailer::Base.deliveries.size
|
79
|
+
TestMailer.deliver_signed_up(@recipient)
|
80
|
+
assert_equal 1, ActionMailer::Base.deliveries.size
|
81
|
+
assert_not_nil ActionMailer::Base.deliveries.first
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_perform_deliveries_flag
|
85
|
+
ActionMailer::Base.perform_deliveries = false
|
86
|
+
TestMailer.deliver_signed_up(@recipient)
|
87
|
+
assert_equal 0, ActionMailer::Base.deliveries.size
|
88
|
+
ActionMailer::Base.perform_deliveries = true
|
89
|
+
TestMailer.deliver_signed_up(@recipient)
|
90
|
+
assert_equal 1, ActionMailer::Base.deliveries.size
|
91
|
+
end
|
92
|
+
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.1
|
|
3
3
|
specification_version: 1
|
4
4
|
name: actionmailer
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2004-
|
6
|
+
version: 0.4.0
|
7
|
+
date: 2004-11-18
|
8
8
|
summary: Service layer for easy email delivery and testing.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -82,5 +82,5 @@ dependencies:
|
|
82
82
|
-
|
83
83
|
- ">="
|
84
84
|
- !ruby/object:Gem::Version
|
85
|
-
version: 0.9.
|
85
|
+
version: 0.9.5
|
86
86
|
version:
|