actionmailer 2.0.5 → 2.1.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 +2 -5
- data/MIT-LICENSE +1 -1
- data/README +14 -10
- data/Rakefile +3 -4
- data/lib/action_mailer.rb +1 -1
- data/lib/action_mailer/adv_attr_accessor.rb +1 -1
- data/lib/action_mailer/base.rb +140 -100
- data/lib/action_mailer/helpers.rb +7 -7
- data/lib/action_mailer/part.rb +2 -2
- data/lib/action_mailer/quoting.rb +3 -1
- data/lib/action_mailer/test_case.rb +14 -22
- data/lib/action_mailer/vendor.rb +2 -2
- data/lib/action_mailer/vendor/text-format-0.6.3/text/format.rb +0 -0
- data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail.rb +1 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/address.rb +426 -0
- data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/attachments.rb +2 -3
- data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/base64.rb +4 -10
- data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/compat.rb +8 -6
- data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/config.rb +2 -6
- data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/core_extensions.rb +14 -18
- data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/encode.rb +77 -19
- data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/header.rb +7 -10
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/index.rb +9 -0
- data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/interface.rb +20 -13
- data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/loader.rb +2 -0
- data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/mail.rb +97 -26
- data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/mailbox.rb +70 -10
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/main.rb +6 -0
- data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/mbox.rb +2 -0
- data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/net.rb +16 -15
- data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/obsolete.rb +7 -12
- data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/parser.rb +1 -0
- data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/port.rb +0 -0
- data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/quoting.rb +0 -0
- data/lib/action_mailer/vendor/tmail-1.2.3/tmail/require_arch.rb +58 -0
- data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/scanner.rb +3 -1
- data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/scanner_r.rb +15 -15
- data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/stringio.rb +1 -0
- data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/utils.rb +89 -32
- data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/version.rb +4 -3
- data/lib/action_mailer/version.rb +2 -2
- data/test/delivery_method_test.rb +1 -1
- data/test/mail_helper_test.rb +1 -1
- data/test/mail_render_test.rb +1 -1
- data/test/mail_service_test.rb +48 -9
- data/test/quoting_test.rb +19 -32
- data/test/test_helper_test.rb +3 -9
- data/test/tmail_test.rb +1 -1
- data/test/url_test.rb +2 -2
- metadata +33 -53
- data/lib/action_mailer/vendor/tmail-1.2.1/tmail/Makefile +0 -19
- data/lib/action_mailer/vendor/tmail-1.2.1/tmail/address.rb +0 -245
- data/lib/action_mailer/vendor/tmail-1.2.1/tmail/facade.rb +0 -552
- data/lib/action_mailer/vendor/tmail-1.2.1/tmail/info.rb +0 -35
- data/lib/action_mailer/vendor/tmail-1.2.1/tmail/parser.y +0 -381
- data/lib/action_mailer/vendor/tmail-1.2.1/tmail/tmail.rb +0 -1
- data/test/fixtures/first_mailer/share.rhtml +0 -0
- data/test/fixtures/helper_mailer/use_example_helper.rhtml +0 -0
- data/test/fixtures/helper_mailer/use_helper.rhtml +0 -0
- data/test/fixtures/helper_mailer/use_helper_method.rhtml +0 -0
- data/test/fixtures/helper_mailer/use_mail_helper.rhtml +0 -0
- data/test/fixtures/path.with.dots/funky_path_mailer/multipart_with_template_path_with_dots.rhtml +0 -0
- data/test/fixtures/path.with.dots/multipart_with_template_path_with_dots.rhtml +0 -0
- data/test/fixtures/raw_base64_decoded_string +0 -0
- data/test/fixtures/raw_base64_encoded_string +0 -1
- data/test/fixtures/second_mailer/share.rhtml +0 -0
- data/test/fixtures/templates/signed_up.rhtml +0 -0
- data/test/fixtures/test_mailer/implicitly_multipart_example.ignored.rhtml +0 -0
- data/test/fixtures/test_mailer/implicitly_multipart_example.text.html.rhtml +0 -0
- data/test/fixtures/test_mailer/implicitly_multipart_example.text.plain.rhtml +0 -0
- data/test/fixtures/test_mailer/implicitly_multipart_example.text.yaml.rhtml +0 -0
- data/test/fixtures/test_mailer/signed_up.rhtml +0 -0
- data/test/fixtures/test_mailer/signed_up_with_url.rhtml +0 -0
data/CHANGELOG
CHANGED
@@ -1,9 +1,6 @@
|
|
1
|
-
*2.0
|
1
|
+
*2.1.0 (May 31st, 2008)*
|
2
2
|
|
3
|
-
*
|
4
|
-
|
5
|
-
|
6
|
-
*2.0.4* (2nd September 2008)
|
3
|
+
* Fixed that a return-path header would be ignored #7572 [joost]
|
7
4
|
|
8
5
|
* Less verbose mail logging: just recipients for :info log level; the whole email for :debug only. #8000 [iaddict, Tarmo Tänav]
|
9
6
|
|
data/MIT-LICENSE
CHANGED
data/README
CHANGED
@@ -19,8 +19,7 @@ are all set up this way. An example of such a method:
|
|
19
19
|
recipients recipient
|
20
20
|
subject "[Signed up] Welcome #{recipient}"
|
21
21
|
from "system@loudthinking.com"
|
22
|
-
|
23
|
-
body(:recipient => recipient)
|
22
|
+
body :recipient => recipient
|
24
23
|
end
|
25
24
|
|
26
25
|
The body of the email is created by using an Action View template (regular
|
@@ -78,21 +77,26 @@ Example:
|
|
78
77
|
end
|
79
78
|
end
|
80
79
|
|
81
|
-
This Mailman can be the target for Postfix. In Rails, you would use the runner
|
80
|
+
This Mailman can be the target for Postfix or other MTAs. In Rails, you would use the runner in the
|
81
|
+
trivial case like this:
|
82
82
|
|
83
83
|
./script/runner 'Mailman.receive(STDIN.read)'
|
84
84
|
|
85
|
+
However, invoking Rails in the runner for each mail to be received is very resource intensive. A single
|
86
|
+
instance of Rails should be run within a daemon if it is going to be utilized to process more than just
|
87
|
+
a limited number of email.
|
88
|
+
|
85
89
|
== Configuration
|
86
90
|
|
87
91
|
The Base class has the full list of configuration options. Here's an example:
|
88
92
|
|
89
|
-
ActionMailer::Base.smtp_settings = {
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
}
|
93
|
+
ActionMailer::Base.smtp_settings = {
|
94
|
+
:address => 'smtp.yourserver.com', # default: localhost
|
95
|
+
:port => '25', # default: 25
|
96
|
+
:user_name => 'user',
|
97
|
+
:password => 'pass',
|
98
|
+
:authentication => :plain # :plain, :login or :cram_md5
|
99
|
+
}
|
96
100
|
|
97
101
|
== Dependencies
|
98
102
|
|
data/Rakefile
CHANGED
@@ -5,7 +5,6 @@ require 'rake/rdoctask'
|
|
5
5
|
require 'rake/packagetask'
|
6
6
|
require 'rake/gempackagetask'
|
7
7
|
require 'rake/contrib/sshpublisher'
|
8
|
-
require 'rake/contrib/rubyforgepublisher'
|
9
8
|
require File.join(File.dirname(__FILE__), 'lib', 'action_mailer', 'version')
|
10
9
|
|
11
10
|
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
|
@@ -56,7 +55,7 @@ spec = Gem::Specification.new do |s|
|
|
56
55
|
s.rubyforge_project = "actionmailer"
|
57
56
|
s.homepage = "http://www.rubyonrails.org"
|
58
57
|
|
59
|
-
s.add_dependency('actionpack', '= 2.0
|
58
|
+
s.add_dependency('actionpack', '= 2.1.0' + PKG_BUILD)
|
60
59
|
|
61
60
|
s.has_rdoc = true
|
62
61
|
s.requirements << 'none'
|
@@ -77,8 +76,7 @@ end
|
|
77
76
|
|
78
77
|
desc "Publish the API documentation"
|
79
78
|
task :pgem => [:package] do
|
80
|
-
Rake::SshFilePublisher.new("
|
81
|
-
`ssh david@greed.loudthinking.com '/u/sites/gems/gemupdate.sh'`
|
79
|
+
Rake::SshFilePublisher.new("davidhh@wrath.rubyonrails.org", "public_html/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
|
82
80
|
end
|
83
81
|
|
84
82
|
desc "Publish the API documentation"
|
@@ -89,6 +87,7 @@ end
|
|
89
87
|
desc "Publish the release files to RubyForge."
|
90
88
|
task :release => [ :package ] do
|
91
89
|
require 'rubyforge'
|
90
|
+
require 'rake/contrib/rubyforgepublisher'
|
92
91
|
|
93
92
|
packages = %w( gem tgz zip ).collect{ |ext| "pkg/#{PKG_NAME}-#{PKG_VERSION}.#{ext}" }
|
94
93
|
|
data/lib/action_mailer.rb
CHANGED
@@ -16,7 +16,7 @@ module ActionMailer
|
|
16
16
|
define_method(name) do |*parameters|
|
17
17
|
raise ArgumentError, "expected 0 or 1 parameters" unless parameters.length <= 1
|
18
18
|
if parameters.empty?
|
19
|
-
if
|
19
|
+
if instance_variable_names.include?(ivar)
|
20
20
|
instance_variable_get(ivar)
|
21
21
|
end
|
22
22
|
else
|
data/lib/action_mailer/base.rb
CHANGED
@@ -5,17 +5,17 @@ require 'action_mailer/utils'
|
|
5
5
|
require 'tmail/net'
|
6
6
|
|
7
7
|
module ActionMailer #:nodoc:
|
8
|
-
#
|
8
|
+
# Action Mailer allows you to send email from your application using a mailer model and views.
|
9
9
|
#
|
10
10
|
#
|
11
11
|
# = Mailer Models
|
12
12
|
#
|
13
|
-
# To use
|
14
|
-
#
|
13
|
+
# To use Action Mailer, you need to create a mailer model.
|
14
|
+
#
|
15
15
|
# $ script/generate mailer Notifier
|
16
16
|
#
|
17
|
-
# The generated model inherits from ActionMailer::Base. Emails are defined by creating methods within the model which are then
|
18
|
-
# used to set variables to be used in the mail template, to change options on the mail, or
|
17
|
+
# The generated model inherits from ActionMailer::Base. Emails are defined by creating methods within the model which are then
|
18
|
+
# used to set variables to be used in the mail template, to change options on the mail, or
|
19
19
|
# to add attachments.
|
20
20
|
#
|
21
21
|
# Examples:
|
@@ -35,25 +35,30 @@ module ActionMailer #:nodoc:
|
|
35
35
|
# * <tt>subject</tt> - The subject of your email. Sets the <tt>Subject:</tt> header.
|
36
36
|
# * <tt>from</tt> - Who the email you are sending is from. Sets the <tt>From:</tt> header.
|
37
37
|
# * <tt>cc</tt> - Takes one or more email addresses. These addresses will receive a carbon copy of your email. Sets the <tt>Cc:</tt> header.
|
38
|
-
# * <tt>bcc</tt> - Takes one or more email
|
38
|
+
# * <tt>bcc</tt> - Takes one or more email addresses. These addresses will receive a blind carbon copy of your email. Sets the <tt>Bcc:</tt> header.
|
39
|
+
# * <tt>reply_to</tt> - Takes one or more email addresses. These addresses will be listed as the default recipients when replying to your email. Sets the <tt>Reply-To:</tt> header.
|
39
40
|
# * <tt>sent_on</tt> - The date on which the message was sent. If not set, the header wil be set by the delivery agent.
|
40
41
|
# * <tt>content_type</tt> - Specify the content type of the message. Defaults to <tt>text/plain</tt>.
|
41
42
|
# * <tt>headers</tt> - Specify additional headers to be set for the message, e.g. <tt>headers 'X-Mail-Count' => 107370</tt>.
|
42
43
|
#
|
44
|
+
# When a <tt>headers 'return-path'</tt> is specified, that value will be used as the 'envelope from'
|
45
|
+
# address. Setting this is useful when you want delivery notifications sent to a different address than
|
46
|
+
# the one in <tt>from</tt>.
|
47
|
+
#
|
43
48
|
# The <tt>body</tt> method has special behavior. It takes a hash which generates an instance variable
|
44
49
|
# named after each key in the hash containing the value that that key points to.
|
45
50
|
#
|
46
|
-
# So, for example, <tt>body
|
47
|
-
# in an instance variable <tt>@account</tt> with the value of <tt>recipient</tt> being accessible in the
|
51
|
+
# So, for example, <tt>body :account => recipient</tt> would result
|
52
|
+
# in an instance variable <tt>@account</tt> with the value of <tt>recipient</tt> being accessible in the
|
48
53
|
# view.
|
49
54
|
#
|
50
55
|
#
|
51
56
|
# = Mailer views
|
52
57
|
#
|
53
|
-
# Like
|
58
|
+
# Like Action Controller, each mailer class has a corresponding view directory
|
54
59
|
# in which each method of the class looks for a template with its name.
|
55
60
|
# To define a template to be used with a mailing, create an <tt>.erb</tt> file with the same name as the method
|
56
|
-
# in your mailer model. For example, in the mailer defined above, the template at
|
61
|
+
# in your mailer model. For example, in the mailer defined above, the template at
|
57
62
|
# <tt>app/views/notifier/signup_notification.erb</tt> would be used to generate the email.
|
58
63
|
#
|
59
64
|
# Variables defined in the model are accessible as instance variables in the view.
|
@@ -67,33 +72,48 @@ module ActionMailer #:nodoc:
|
|
67
72
|
#
|
68
73
|
# You got a new note!
|
69
74
|
# <%= truncate(note.body, 25) %>
|
70
|
-
#
|
71
75
|
#
|
72
|
-
# = Generating URLs for mailer views
|
73
76
|
#
|
74
|
-
#
|
75
|
-
# Unlike controllers from Action Pack, the mailer instance doesn't have any context about the incoming request. That's
|
76
|
-
# why you need to jump this little hoop and supply all the details needed for the URL. Example:
|
77
|
+
# = Generating URLs
|
77
78
|
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
#
|
82
|
-
#
|
83
|
-
#
|
84
|
-
#
|
79
|
+
# URLs can be generated in mailer views using <tt>url_for</tt> or named routes.
|
80
|
+
# Unlike controllers from Action Pack, the mailer instance doesn't have any context about the incoming request,
|
81
|
+
# so you'll need to provide all of the details needed to generate a URL.
|
82
|
+
#
|
83
|
+
# When using <tt>url_for</tt> you'll need to provide the <tt>:host</tt>, <tt>:controller</tt>, and <tt>:action</tt>:
|
84
|
+
#
|
85
|
+
# <%= url_for(:host => "example.com", :controller => "welcome", :action => "greeting") %>
|
86
|
+
#
|
87
|
+
# When using named routes you only need to supply the <tt>:host</tt>:
|
88
|
+
#
|
89
|
+
# <%= users_url(:host => "example.com") %>
|
90
|
+
#
|
91
|
+
# You will want to avoid using the <tt>name_of_route_path</tt> form of named routes because it doesn't make sense to
|
92
|
+
# generate relative URLs in email messages.
|
85
93
|
#
|
86
|
-
#
|
94
|
+
# It is also possible to set a default host that will be used in all mailers by setting the <tt>:host</tt> option in
|
95
|
+
# the <tt>ActionMailer::Base.default_url_options</tt> hash as follows:
|
96
|
+
#
|
97
|
+
# ActionMailer::Base.default_url_options[:host] = "example.com"
|
98
|
+
#
|
99
|
+
# This can also be set as a configuration option in <tt>config/environment.rb</tt>:
|
100
|
+
#
|
101
|
+
# config.action_mailer.default_url_options = { :host => "example.com" }
|
102
|
+
#
|
103
|
+
# If you do decide to set a default <tt>:host</tt> for your mailers you will want to use the
|
104
|
+
# <tt>:only_path => false</tt> option when using <tt>url_for</tt>. This will ensure that absolute URLs are generated because
|
105
|
+
# the <tt>url_for</tt> view helper will, by default, generate relative URLs when a <tt>:host</tt> option isn't
|
106
|
+
# explicitly provided.
|
87
107
|
#
|
88
108
|
# = Sending mail
|
89
109
|
#
|
90
|
-
# Once a mailer action and template are defined, you can deliver your message or create it and save it
|
110
|
+
# Once a mailer action and template are defined, you can deliver your message or create it and save it
|
91
111
|
# for delivery later:
|
92
112
|
#
|
93
113
|
# Notifier.deliver_signup_notification(david) # sends the email
|
94
114
|
# mail = Notifier.create_signup_notification(david) # => a tmail object
|
95
115
|
# Notifier.deliver(mail)
|
96
|
-
#
|
116
|
+
#
|
97
117
|
# You never instantiate your mailer class. Rather, your delivery instance
|
98
118
|
# methods are automatically wrapped in class methods that start with the word
|
99
119
|
# <tt>deliver_</tt> followed by the name of the mailer method that you would
|
@@ -108,13 +128,13 @@ module ActionMailer #:nodoc:
|
|
108
128
|
#
|
109
129
|
# class MyMailer < ActionMailer::Base
|
110
130
|
# def signup_notification(recipient)
|
111
|
-
# recipients
|
112
|
-
# subject
|
113
|
-
#
|
114
|
-
#
|
115
|
-
# content_type "text/html"
|
131
|
+
# recipients recipient.email_address_with_name
|
132
|
+
# subject "New account information"
|
133
|
+
# from "system@example.com"
|
134
|
+
# body :account => recipient
|
135
|
+
# content_type "text/html"
|
116
136
|
# end
|
117
|
-
# end
|
137
|
+
# end
|
118
138
|
#
|
119
139
|
#
|
120
140
|
# = Multipart email
|
@@ -126,6 +146,7 @@ module ActionMailer #:nodoc:
|
|
126
146
|
# recipients recipient.email_address_with_name
|
127
147
|
# subject "New account information"
|
128
148
|
# from "system@example.com"
|
149
|
+
# content_type "multipart/alternative"
|
129
150
|
#
|
130
151
|
# part :content_type => "text/html",
|
131
152
|
# :body => render_message("signup-as-html", :account => recipient)
|
@@ -136,21 +157,26 @@ module ActionMailer #:nodoc:
|
|
136
157
|
# end
|
137
158
|
# end
|
138
159
|
# end
|
139
|
-
#
|
140
|
-
# Multipart messages can also be used implicitly because
|
160
|
+
#
|
161
|
+
# Multipart messages can also be used implicitly because Action Mailer will automatically
|
141
162
|
# detect and use multipart templates, where each template is named after the name of the action, followed
|
142
163
|
# by the content type. Each such detected template will be added as separate part to the message.
|
143
|
-
#
|
164
|
+
#
|
144
165
|
# For example, if the following templates existed:
|
145
166
|
# * signup_notification.text.plain.erb
|
146
167
|
# * signup_notification.text.html.erb
|
147
168
|
# * signup_notification.text.xml.builder
|
148
169
|
# * signup_notification.text.x-yaml.erb
|
149
|
-
#
|
170
|
+
#
|
150
171
|
# Each would be rendered and added as a separate part to the message,
|
151
|
-
# with the corresponding content type. The
|
152
|
-
#
|
172
|
+
# with the corresponding content type. The content type for the entire
|
173
|
+
# message is automatically set to <tt>multipart/alternative</tt>, which indicates
|
174
|
+
# that the email contains multiple different representations of the same email
|
175
|
+
# body. The same body hash is passed to each template.
|
153
176
|
#
|
177
|
+
# Implicit template rendering is not performed if any attachments or parts have been added to the email.
|
178
|
+
# This means that you'll have to manually add each part to the email and set the content type of the email
|
179
|
+
# to <tt>multipart/alternative</tt>.
|
154
180
|
#
|
155
181
|
# = Attachments
|
156
182
|
#
|
@@ -172,51 +198,52 @@ module ActionMailer #:nodoc:
|
|
172
198
|
# a.body = generate_your_pdf_here()
|
173
199
|
# end
|
174
200
|
# end
|
175
|
-
# end
|
201
|
+
# end
|
176
202
|
#
|
177
203
|
#
|
178
204
|
# = Configuration options
|
179
205
|
#
|
180
206
|
# These options are specified on the class level, like <tt>ActionMailer::Base.template_root = "/my/templates"</tt>
|
181
207
|
#
|
182
|
-
# * <tt>template_root</tt> -
|
208
|
+
# * <tt>template_root</tt> - Determines the base from which template references will be made.
|
183
209
|
#
|
184
210
|
# * <tt>logger</tt> - the logger is used for generating information on the mailing run if available.
|
185
211
|
# Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers.
|
186
212
|
#
|
187
|
-
# * <tt>smtp_settings</tt> -
|
188
|
-
# * <tt>:address</tt> Allows you to use a remote mail server. Just change it from its default "localhost" setting.
|
189
|
-
# * <tt>:port</tt> On the off chance that your mail server doesn't run on port 25, you can change it.
|
190
|
-
# * <tt>:domain</tt> If you need to specify a HELO domain, you can do it here.
|
191
|
-
# * <tt>:user_name</tt> If your mail server requires authentication, set the username in this setting.
|
192
|
-
# * <tt>:password</tt> If your mail server requires authentication, set the password in this setting.
|
193
|
-
# * <tt>:authentication</tt> If your mail server requires authentication, you need to specify the authentication type here.
|
194
|
-
# This is a symbol and one of
|
213
|
+
# * <tt>smtp_settings</tt> - Allows detailed configuration for <tt>:smtp</tt> delivery method:
|
214
|
+
# * <tt>:address</tt> - Allows you to use a remote mail server. Just change it from its default "localhost" setting.
|
215
|
+
# * <tt>:port</tt> - On the off chance that your mail server doesn't run on port 25, you can change it.
|
216
|
+
# * <tt>:domain</tt> - If you need to specify a HELO domain, you can do it here.
|
217
|
+
# * <tt>:user_name</tt> - If your mail server requires authentication, set the username in this setting.
|
218
|
+
# * <tt>:password</tt> - If your mail server requires authentication, set the password in this setting.
|
219
|
+
# * <tt>:authentication</tt> - If your mail server requires authentication, you need to specify the authentication type here.
|
220
|
+
# This is a symbol and one of <tt>:plain</tt>, <tt>:login</tt>, <tt>:cram_md5</tt>.
|
221
|
+
#
|
222
|
+
# * <tt>sendmail_settings</tt> - Allows you to override options for the <tt>:sendmail</tt> delivery method.
|
223
|
+
# * <tt>:location</tt> - The location of the sendmail executable. Defaults to <tt>/usr/sbin/sendmail</tt>.
|
224
|
+
# * <tt>:arguments</tt> - The command line arguments. Defaults to <tt>-i -t</tt>.
|
195
225
|
#
|
196
|
-
# * <tt>
|
197
|
-
# * <tt>:location</tt> The location of the sendmail executable, defaults to "/usr/sbin/sendmail"
|
198
|
-
# * <tt>:arguments</tt> The command line arguments
|
199
|
-
# * <tt>raise_delivery_errors</tt> - whether or not errors should be raised if the email fails to be delivered.
|
226
|
+
# * <tt>raise_delivery_errors</tt> - Whether or not errors should be raised if the email fails to be delivered.
|
200
227
|
#
|
201
|
-
# * <tt>delivery_method</tt> - Defines a delivery method. Possible values are
|
228
|
+
# * <tt>delivery_method</tt> - Defines a delivery method. Possible values are <tt>:smtp</tt> (default), <tt>:sendmail</tt>, and <tt>:test</tt>.
|
202
229
|
#
|
203
|
-
# * <tt>perform_deliveries</tt> - Determines whether deliver_
|
230
|
+
# * <tt>perform_deliveries</tt> - Determines whether <tt>deliver_*</tt> methods are actually carried out. By default they are,
|
204
231
|
# but this can be turned off to help functional testing.
|
205
232
|
#
|
206
|
-
# * <tt>deliveries</tt> - Keeps an array of all the emails sent out through the Action Mailer with delivery_method :test
|
233
|
+
# * <tt>deliveries</tt> - Keeps an array of all the emails sent out through the Action Mailer with <tt>delivery_method :test</tt>. Most useful
|
207
234
|
# for unit and functional testing.
|
208
235
|
#
|
209
236
|
# * <tt>default_charset</tt> - The default charset used for the body and to encode the subject. Defaults to UTF-8. You can also
|
210
|
-
# pick a different charset from inside a method with
|
237
|
+
# pick a different charset from inside a method with +charset+.
|
211
238
|
# * <tt>default_content_type</tt> - The default content type used for the main part of the message. Defaults to "text/plain". You
|
212
|
-
# can also pick a different content type from inside a method with
|
213
|
-
# * <tt>default_mime_version</tt> - The default mime version used for the message. Defaults to
|
214
|
-
# can also pick a different value from inside a method with
|
239
|
+
# can also pick a different content type from inside a method with +content_type+.
|
240
|
+
# * <tt>default_mime_version</tt> - The default mime version used for the message. Defaults to <tt>1.0</tt>. You
|
241
|
+
# can also pick a different value from inside a method with +mime_version+.
|
215
242
|
# * <tt>default_implicit_parts_order</tt> - When a message is built implicitly (i.e. multiple parts are assembled from templates
|
216
243
|
# which specify the content type in their filenames) this variable controls how the parts are ordered. Defaults to
|
217
|
-
# ["text/html", "text/enriched", "text/plain"]
|
244
|
+
# <tt>["text/html", "text/enriched", "text/plain"]</tt>. Items that appear first in the array have higher priority in the mail client
|
218
245
|
# and appear last in the mime encoded message. You can also pick a different order from inside a method with
|
219
|
-
#
|
246
|
+
# +implicit_parts_order+.
|
220
247
|
class Base
|
221
248
|
include AdvAttrAccessor, PartContainer
|
222
249
|
include ActionController::UrlWriter if Object.const_defined?(:ActionController)
|
@@ -229,16 +256,16 @@ module ActionMailer #:nodoc:
|
|
229
256
|
cattr_accessor :template_extensions
|
230
257
|
@@template_extensions = ['erb', 'builder', 'rhtml', 'rxml']
|
231
258
|
|
232
|
-
@@smtp_settings = {
|
233
|
-
:address => "localhost",
|
234
|
-
:port => 25,
|
235
|
-
:domain => 'localhost.localdomain',
|
236
|
-
:user_name => nil,
|
237
|
-
:password => nil,
|
259
|
+
@@smtp_settings = {
|
260
|
+
:address => "localhost",
|
261
|
+
:port => 25,
|
262
|
+
:domain => 'localhost.localdomain',
|
263
|
+
:user_name => nil,
|
264
|
+
:password => nil,
|
238
265
|
:authentication => nil
|
239
266
|
}
|
240
267
|
cattr_accessor :smtp_settings
|
241
|
-
|
268
|
+
|
242
269
|
@@sendmail_settings = {
|
243
270
|
:location => '/usr/sbin/sendmail',
|
244
271
|
:arguments => '-i -t'
|
@@ -250,10 +277,10 @@ module ActionMailer #:nodoc:
|
|
250
277
|
|
251
278
|
superclass_delegating_accessor :delivery_method
|
252
279
|
self.delivery_method = :smtp
|
253
|
-
|
280
|
+
|
254
281
|
@@perform_deliveries = true
|
255
282
|
cattr_accessor :perform_deliveries
|
256
|
-
|
283
|
+
|
257
284
|
@@deliveries = []
|
258
285
|
cattr_accessor :deliveries
|
259
286
|
|
@@ -262,7 +289,7 @@ module ActionMailer #:nodoc:
|
|
262
289
|
|
263
290
|
@@default_content_type = "text/plain"
|
264
291
|
cattr_accessor :default_content_type
|
265
|
-
|
292
|
+
|
266
293
|
@@default_mime_version = "1.0"
|
267
294
|
cattr_accessor :default_mime_version
|
268
295
|
|
@@ -271,47 +298,51 @@ module ActionMailer #:nodoc:
|
|
271
298
|
|
272
299
|
# Specify the BCC addresses for the message
|
273
300
|
adv_attr_accessor :bcc
|
274
|
-
|
301
|
+
|
275
302
|
# Define the body of the message. This is either a Hash (in which case it
|
276
303
|
# specifies the variables to pass to the template when it is rendered),
|
277
304
|
# or a string, in which case it specifies the actual text of the message.
|
278
305
|
adv_attr_accessor :body
|
279
|
-
|
306
|
+
|
280
307
|
# Specify the CC addresses for the message.
|
281
308
|
adv_attr_accessor :cc
|
282
|
-
|
309
|
+
|
283
310
|
# Specify the charset to use for the message. This defaults to the
|
284
311
|
# +default_charset+ specified for ActionMailer::Base.
|
285
312
|
adv_attr_accessor :charset
|
286
|
-
|
313
|
+
|
287
314
|
# Specify the content type for the message. This defaults to <tt>text/plain</tt>
|
288
315
|
# in most cases, but can be automatically set in some situations.
|
289
316
|
adv_attr_accessor :content_type
|
290
|
-
|
317
|
+
|
291
318
|
# Specify the from address for the message.
|
292
319
|
adv_attr_accessor :from
|
293
|
-
|
320
|
+
|
321
|
+
# Specify the address (if different than the "from" address) to direct
|
322
|
+
# replies to this message.
|
323
|
+
adv_attr_accessor :reply_to
|
324
|
+
|
294
325
|
# Specify additional headers to be added to the message.
|
295
326
|
adv_attr_accessor :headers
|
296
|
-
|
327
|
+
|
297
328
|
# Specify the order in which parts should be sorted, based on content-type.
|
298
329
|
# This defaults to the value for the +default_implicit_parts_order+.
|
299
330
|
adv_attr_accessor :implicit_parts_order
|
300
|
-
|
331
|
+
|
301
332
|
# Defaults to "1.0", but may be explicitly given if needed.
|
302
333
|
adv_attr_accessor :mime_version
|
303
|
-
|
334
|
+
|
304
335
|
# The recipient addresses for the message, either as a string (for a single
|
305
336
|
# address) or an array (for multiple addresses).
|
306
337
|
adv_attr_accessor :recipients
|
307
|
-
|
338
|
+
|
308
339
|
# The date on which the message was sent. If not set (the default), the
|
309
340
|
# header will be set by the delivery agent.
|
310
341
|
adv_attr_accessor :sent_on
|
311
|
-
|
342
|
+
|
312
343
|
# Specify the subject of the message.
|
313
344
|
adv_attr_accessor :subject
|
314
|
-
|
345
|
+
|
315
346
|
# Specify the template name to use for current message. This is the "base"
|
316
347
|
# template name, without the extension or directory, and may be used to
|
317
348
|
# have multiple mailer methods share the same template.
|
@@ -327,7 +358,7 @@ module ActionMailer #:nodoc:
|
|
327
358
|
self.class.mailer_name
|
328
359
|
end
|
329
360
|
end
|
330
|
-
|
361
|
+
|
331
362
|
def mailer_name=(value)
|
332
363
|
self.class.mailer_name = value
|
333
364
|
end
|
@@ -357,8 +388,8 @@ module ActionMailer #:nodoc:
|
|
357
388
|
|
358
389
|
# Receives a raw email, parses it into an email object, decodes it,
|
359
390
|
# instantiates a new mailer, and passes the email object to the mailer
|
360
|
-
# object's
|
361
|
-
# process incoming messages, you'll need to implement a
|
391
|
+
# object's +receive+ method. If you want your mailer to be able to
|
392
|
+
# process incoming messages, you'll need to implement a +receive+
|
362
393
|
# method that accepts the email object as a parameter:
|
363
394
|
#
|
364
395
|
# class MyMailer < ActionMailer::Base
|
@@ -387,12 +418,17 @@ module ActionMailer #:nodoc:
|
|
387
418
|
# templating language other than rhtml or rxml are supported.
|
388
419
|
# To use this, include in your template-language plugin's init
|
389
420
|
# code or on a per-application basis, this can be invoked from
|
390
|
-
# config/environment.rb
|
421
|
+
# <tt>config/environment.rb</tt>:
|
391
422
|
#
|
392
423
|
# ActionMailer::Base.register_template_extension('haml')
|
393
424
|
def register_template_extension(extension)
|
394
425
|
template_extensions << extension
|
395
426
|
end
|
427
|
+
|
428
|
+
def template_root=(root)
|
429
|
+
write_inheritable_attribute(:template_root, root)
|
430
|
+
ActionView::TemplateFinder.process_view_paths(root)
|
431
|
+
end
|
396
432
|
end
|
397
433
|
|
398
434
|
# Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer
|
@@ -400,7 +436,7 @@ module ActionMailer #:nodoc:
|
|
400
436
|
# remain uninitialized (useful when you only need to invoke the "receive"
|
401
437
|
# method, for instance).
|
402
438
|
def initialize(method_name=nil, *parameters) #:nodoc:
|
403
|
-
create!(method_name, *parameters) if method_name
|
439
|
+
create!(method_name, *parameters) if method_name
|
404
440
|
end
|
405
441
|
|
406
442
|
# Initialize the mailer via the given +method_name+. The body will be
|
@@ -459,12 +495,12 @@ module ActionMailer #:nodoc:
|
|
459
495
|
end
|
460
496
|
|
461
497
|
# Delivers a TMail::Mail object. By default, it delivers the cached mail
|
462
|
-
# object (from the
|
498
|
+
# object (from the <tt>create!</tt> method). If no cached mail object exists, and
|
463
499
|
# no alternate has been given as the parameter, this will fail.
|
464
500
|
def deliver!(mail = @mail)
|
465
501
|
raise "no mail object available for delivery!" unless mail
|
466
502
|
unless logger.nil?
|
467
|
-
logger.info "Sent mail to #{recipients.
|
503
|
+
logger.info "Sent mail to #{Array(recipients).join(', ')}"
|
468
504
|
logger.debug "\n#{mail.encoded}"
|
469
505
|
end
|
470
506
|
|
@@ -486,7 +522,7 @@ module ActionMailer #:nodoc:
|
|
486
522
|
@content_type ||= @@default_content_type.dup
|
487
523
|
@implicit_parts_order ||= @@default_implicit_parts_order.dup
|
488
524
|
@template ||= method_name
|
489
|
-
@mailer_name ||=
|
525
|
+
@mailer_name ||= self.class.name.underscore
|
490
526
|
@parts ||= []
|
491
527
|
@headers ||= {}
|
492
528
|
@body ||= {}
|
@@ -545,13 +581,14 @@ module ActionMailer #:nodoc:
|
|
545
581
|
def create_mail
|
546
582
|
m = TMail::Mail.new
|
547
583
|
|
548
|
-
m.subject,
|
549
|
-
m.to, m.from
|
550
|
-
m.bcc
|
551
|
-
m.cc
|
552
|
-
|
584
|
+
m.subject, = quote_any_if_necessary(charset, subject)
|
585
|
+
m.to, m.from = quote_any_address_if_necessary(charset, recipients, from)
|
586
|
+
m.bcc = quote_address_if_necessary(bcc, charset) unless bcc.nil?
|
587
|
+
m.cc = quote_address_if_necessary(cc, charset) unless cc.nil?
|
588
|
+
m.reply_to = quote_address_if_necessary(reply_to, charset) unless reply_to.nil?
|
553
589
|
m.mime_version = mime_version unless mime_version.nil?
|
554
|
-
m.date
|
590
|
+
m.date = sent_on.to_time rescue sent_on if sent_on
|
591
|
+
|
555
592
|
headers.each { |k, v| m[k] = v }
|
556
593
|
|
557
594
|
real_content_type, ctype_attrs = parse_content_type
|
@@ -572,7 +609,7 @@ module ActionMailer #:nodoc:
|
|
572
609
|
part = (TMail::Mail === p ? p : p.to_mail(self))
|
573
610
|
m.parts << part
|
574
611
|
end
|
575
|
-
|
612
|
+
|
576
613
|
if real_content_type =~ /multipart/
|
577
614
|
ctype_attrs.delete "charset"
|
578
615
|
m.set_content_type(real_content_type, nil, ctype_attrs)
|
@@ -585,15 +622,18 @@ module ActionMailer #:nodoc:
|
|
585
622
|
def perform_delivery_smtp(mail)
|
586
623
|
destinations = mail.destinations
|
587
624
|
mail.ready_to_send
|
625
|
+
sender = mail['return-path'] || mail.from
|
588
626
|
|
589
|
-
Net::SMTP.start(smtp_settings[:address], smtp_settings[:port], smtp_settings[:domain],
|
627
|
+
Net::SMTP.start(smtp_settings[:address], smtp_settings[:port], smtp_settings[:domain],
|
590
628
|
smtp_settings[:user_name], smtp_settings[:password], smtp_settings[:authentication]) do |smtp|
|
591
|
-
smtp.sendmail(mail.encoded,
|
629
|
+
smtp.sendmail(mail.encoded, sender, destinations)
|
592
630
|
end
|
593
631
|
end
|
594
632
|
|
595
633
|
def perform_delivery_sendmail(mail)
|
596
|
-
|
634
|
+
sendmail_args = sendmail_settings[:arguments]
|
635
|
+
sendmail_args += " -f \"#{mail['return-path']}\"" if mail['return-path']
|
636
|
+
IO.popen("#{sendmail_settings[:location]} #{sendmail_args}","w+") do |sm|
|
597
637
|
sm.print(mail.encoded.gsub(/\r/, ''))
|
598
638
|
sm.flush
|
599
639
|
end
|