actionmailer 3.2.22.5 → 4.0.0.beta1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +36 -107
- data/MIT-LICENSE +1 -1
- data/README.rdoc +20 -18
- data/lib/action_mailer.rb +6 -8
- data/lib/action_mailer/base.rb +145 -100
- data/lib/action_mailer/collector.rb +4 -4
- data/lib/action_mailer/delivery_methods.rb +21 -24
- data/lib/action_mailer/log_subscriber.rb +5 -5
- data/lib/action_mailer/mail_helper.rb +6 -8
- data/lib/action_mailer/railtie.rb +2 -2
- data/lib/action_mailer/test_case.rb +7 -4
- data/lib/action_mailer/test_helper.rb +8 -9
- data/lib/action_mailer/version.rb +4 -4
- data/lib/rails/generators/mailer/USAGE +4 -5
- data/lib/rails/generators/mailer/mailer_generator.rb +1 -1
- data/lib/rails/generators/mailer/templates/mailer.rb +3 -3
- metadata +16 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d998e51a81263ea8d899918f19f535a7c53c9fcd
|
4
|
+
data.tar.gz: cae501c3d36339904aafde7187eb48ec9e7fd54b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19b5d72a2aea5a58b284535609cec0c1834ee99238049ad57185cc4791dc6af3476ddd66324ddb9b4c4c9f695c7ea02ee797a284309c65c60e7a4b1634085dea
|
7
|
+
data.tar.gz: a0d0ada11072b71c20f91b79893d5929dda7283385b67faf8bbde4bb4a88240429fe32e3783f0a3cb7227107db8cff2d3dbde031ddf4bf670aebea0a0ae43321
|
data/CHANGELOG.md
CHANGED
@@ -1,128 +1,57 @@
|
|
1
|
-
## Rails
|
1
|
+
## Rails 4.0.0.beta1 (February 25, 2013) ##
|
2
2
|
|
3
|
-
*
|
3
|
+
* Allow passing interpolations to `#default_i18n_subject`, e.g.:
|
4
4
|
|
5
|
+
# config/locales/en.yml
|
6
|
+
en:
|
7
|
+
user_mailer:
|
8
|
+
welcome:
|
9
|
+
subject: 'Hello, %{username}'
|
5
10
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
## Rails 3.2.18 (May 6, 2014) ##
|
12
|
-
|
13
|
-
* No changes.
|
14
|
-
|
15
|
-
|
16
|
-
## Rails 3.2.17 (Feb 18, 2014) ##
|
17
|
-
|
18
|
-
* No changes.
|
19
|
-
|
20
|
-
|
21
|
-
## Rails 3.2.16 (Dec 3, 2013) ##
|
22
|
-
|
23
|
-
* No changes.
|
24
|
-
|
25
|
-
|
26
|
-
## Rails 3.2.15 (Oct 16, 2013) ##
|
27
|
-
|
28
|
-
* No changes.
|
29
|
-
|
30
|
-
## Rails 3.2.14 (Jul 22, 2013) ##
|
31
|
-
|
32
|
-
* No changes.
|
33
|
-
|
34
|
-
|
35
|
-
## Rails 3.2.13 (Mar 18, 2013) ##
|
36
|
-
|
37
|
-
* No changes.
|
38
|
-
|
39
|
-
|
40
|
-
## Rails 3.2.12 (Feb 11, 2013) ##
|
41
|
-
|
42
|
-
* No changes.
|
43
|
-
|
44
|
-
|
45
|
-
## Rails 3.2.11 (Jan 8, 2013) ##
|
46
|
-
|
47
|
-
* No changes.
|
48
|
-
|
49
|
-
|
50
|
-
## Rails 3.2.10 (Jan 2, 2013) ##
|
51
|
-
|
52
|
-
* No changes.
|
53
|
-
|
54
|
-
|
55
|
-
## Rails 3.2.9 (Nov 12, 2012) ##
|
56
|
-
|
57
|
-
* The return value from mailer methods is no longer relevant. This fixes a bug,
|
58
|
-
which was introduced with 3.2.9.
|
59
|
-
Backport #8450
|
60
|
-
Fix #8448
|
61
|
-
|
62
|
-
class ExampleMailer < ActionMailer::Base
|
63
|
-
# in 3.2.9, returning a falsy value from a mailer action, prevented the email from beeing sent.
|
64
|
-
# With 3.2.10 the return value is no longer relevant. If you call mail() the email will be sent.
|
65
|
-
def nil_returning_mailer_action
|
66
|
-
mail()
|
67
|
-
nil
|
11
|
+
# app/mailers/user_mailer.rb
|
12
|
+
class UserMailer < ActionMailer::Base
|
13
|
+
def welcome(user)
|
14
|
+
mail(subject: default_i18n_subject(username: user.name))
|
68
15
|
end
|
69
16
|
end
|
70
17
|
|
71
|
-
*
|
18
|
+
*Olek Janiszewski*
|
72
19
|
|
20
|
+
* Eager loading made to use relation's `in_clause_length` instead of host's one.
|
21
|
+
Fix #8474
|
73
22
|
|
74
|
-
|
23
|
+
*Boris Staal*
|
24
|
+
|
25
|
+
* Explicit multipart messages no longer set the order of the MIME parts.
|
26
|
+
*Nate Berkopec*
|
75
27
|
|
76
28
|
* Do not render views when mail() isn't called.
|
77
29
|
Fix #7761
|
78
30
|
|
79
31
|
*Yves Senn*
|
80
32
|
|
33
|
+
* Allow delivery method options to be set per mail instance *Aditya Sanghi*
|
81
34
|
|
82
|
-
|
83
|
-
|
84
|
-
* No changes.
|
85
|
-
|
86
|
-
|
87
|
-
## Rails 3.2.7 (Jul 26, 2012) ##
|
88
|
-
|
89
|
-
* No changes.
|
90
|
-
|
91
|
-
|
92
|
-
## Rails 3.2.6 (Jun 12, 2012) ##
|
93
|
-
|
94
|
-
* No changes.
|
95
|
-
|
96
|
-
|
97
|
-
## Rails 3.2.5 (Jun 1, 2012) ##
|
35
|
+
If your smtp delivery settings are dynamic,
|
36
|
+
you can now override settings per mail instance for e.g.
|
98
37
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
* No changes.
|
105
|
-
|
106
|
-
|
107
|
-
## Rails 3.2.3 (March 30, 2012) ##
|
108
|
-
|
109
|
-
* Upgrade mail version to 2.4.3 *ML*
|
110
|
-
|
111
|
-
|
112
|
-
## Rails 3.2.2 (March 1, 2012) ##
|
113
|
-
|
114
|
-
* No changes.
|
115
|
-
|
116
|
-
|
117
|
-
## Rails 3.2.1 (January 26, 2012) ##
|
118
|
-
|
119
|
-
* No changes.
|
38
|
+
def my_mailer(user,company)
|
39
|
+
mail to: user.email, subject: "Welcome!",
|
40
|
+
delivery_method_options: { user_name: company.smtp_user,
|
41
|
+
password: company.smtp_password }
|
42
|
+
end
|
120
43
|
|
44
|
+
This will ensure that your default SMTP settings will be overridden
|
45
|
+
by the company specific ones. You only have to override the settings
|
46
|
+
that are dynamic and leave the static setting in your environment
|
47
|
+
configuration file (e.g. config/environments/production.rb)
|
121
48
|
|
122
|
-
|
49
|
+
* Allow to set default Action Mailer options via `config.action_mailer.default_options=` *Robert Pankowecki*
|
123
50
|
|
124
|
-
*
|
51
|
+
* Raise an `ActionView::MissingTemplate` exception when no implicit template could be found. *Damien Mathieu*
|
125
52
|
|
126
|
-
*
|
53
|
+
* Allow callbacks to be defined in mailers similar to `ActionController::Base`. You can configure default
|
54
|
+
settings, headers, attachments, delivery settings or change delivery using
|
55
|
+
`before_filter`, `after_filter` etc. *Justin S. Leitgeb*
|
127
56
|
|
128
|
-
Please check [3-
|
57
|
+
Please check [3-2-stable](https://github.com/rails/rails/blob/3-2-stable/actionmailer/CHANGELOG.md) for previous changes.
|
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -22,12 +22,12 @@ the email.
|
|
22
22
|
This can be as simple as:
|
23
23
|
|
24
24
|
class Notifier < ActionMailer::Base
|
25
|
-
|
25
|
+
default from: 'system@loudthinking.com'
|
26
26
|
|
27
27
|
def welcome(recipient)
|
28
28
|
@recipient = recipient
|
29
|
-
mail(:
|
30
|
-
:
|
29
|
+
mail(to: recipient,
|
30
|
+
subject: "[Signed up] Welcome #{recipient}")
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -42,7 +42,7 @@ So the corresponding body template for the method above could look like this:
|
|
42
42
|
|
43
43
|
Thank you for signing up!
|
44
44
|
|
45
|
-
|
45
|
+
If the recipient was given as "david@loudthinking.com", the email
|
46
46
|
generated would look like this:
|
47
47
|
|
48
48
|
Date: Mon, 25 Jan 2010 22:48:09 +1100
|
@@ -62,7 +62,7 @@ generated would look like this:
|
|
62
62
|
Thank you for signing up!
|
63
63
|
|
64
64
|
In previous version of Rails you would call <tt>create_method_name</tt> and
|
65
|
-
<tt>deliver_method_name</tt>. Rails 3.0 has a much simpler interface
|
65
|
+
<tt>deliver_method_name</tt>. Rails 3.0 has a much simpler interface - you
|
66
66
|
simply call the method and optionally call +deliver+ on the return value.
|
67
67
|
|
68
68
|
Calling the method returns a Mail Message object:
|
@@ -76,14 +76,14 @@ Or you can just chain the methods together like:
|
|
76
76
|
|
77
77
|
== Setting defaults
|
78
78
|
|
79
|
-
It is possible to set default values that will be used in every method in your Action Mailer class. To implement this functionality, you just call the public class method <tt>default</tt> which you get for free from ActionMailer::Base. This method accepts a Hash as the parameter. You can use any of the headers e-mail messages has, like <tt>:from</tt> as the key. You can also pass in a string as the key, like "Content-Type", but Action Mailer does this out of the box for you, so you won't need to worry about that. Finally it is also possible to pass in a Proc that will get evaluated when it is needed.
|
79
|
+
It is possible to set default values that will be used in every method in your Action Mailer class. To implement this functionality, you just call the public class method <tt>default</tt> which you get for free from ActionMailer::Base. This method accepts a Hash as the parameter. You can use any of the headers e-mail messages has, like <tt>:from</tt> as the key. You can also pass in a string as the key, like "Content-Type", but Action Mailer does this out of the box for you, so you won't need to worry about that. Finally, it is also possible to pass in a Proc that will get evaluated when it is needed.
|
80
80
|
|
81
81
|
Note that every value you set with this method will get over written if you use the same key in your mailer method.
|
82
82
|
|
83
83
|
Example:
|
84
84
|
|
85
|
-
class
|
86
|
-
default :
|
85
|
+
class AuthenticationMailer < ActionMailer::Base
|
86
|
+
default from: "awesome@application.com", subject: Proc.new { "E-mail was generated at #{Time.now}" }
|
87
87
|
.....
|
88
88
|
end
|
89
89
|
|
@@ -98,15 +98,15 @@ Example:
|
|
98
98
|
|
99
99
|
class Mailman < ActionMailer::Base
|
100
100
|
def receive(email)
|
101
|
-
page = Page.
|
101
|
+
page = Page.find_by(address: email.to.first)
|
102
102
|
page.emails.create(
|
103
|
-
:
|
103
|
+
subject: email.subject, body: email.body
|
104
104
|
)
|
105
105
|
|
106
106
|
if email.has_attachments?
|
107
107
|
email.attachments.each do |attachment|
|
108
108
|
page.attachments.create({
|
109
|
-
:
|
109
|
+
file: attachment, description: email.subject
|
110
110
|
})
|
111
111
|
end
|
112
112
|
end
|
@@ -127,11 +127,11 @@ a limited number of email.
|
|
127
127
|
The Base class has the full list of configuration options. Here's an example:
|
128
128
|
|
129
129
|
ActionMailer::Base.smtp_settings = {
|
130
|
-
:
|
131
|
-
:
|
132
|
-
:
|
133
|
-
:
|
134
|
-
:
|
130
|
+
address: 'smtp.yourserver.com', # default: localhost
|
131
|
+
port: '25', # default: 25
|
132
|
+
user_name: 'user',
|
133
|
+
password: 'pass',
|
134
|
+
authentication: :plain # :plain, :login or :cram_md5
|
135
135
|
}
|
136
136
|
|
137
137
|
|
@@ -143,12 +143,14 @@ The latest version of Action Mailer can be installed with RubyGems:
|
|
143
143
|
|
144
144
|
Source code can be downloaded as part of the Rails project on GitHub
|
145
145
|
|
146
|
-
* https://github.com/rails/rails/tree/
|
146
|
+
* https://github.com/rails/rails/tree/master/actionmailer
|
147
147
|
|
148
148
|
|
149
149
|
== License
|
150
150
|
|
151
|
-
Action Mailer is released under the MIT license
|
151
|
+
Action Mailer is released under the MIT license:
|
152
|
+
|
153
|
+
* http://www.opensource.org/licenses/MIT
|
152
154
|
|
153
155
|
|
154
156
|
== Support
|
data/lib/action_mailer.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2004-
|
2
|
+
# Copyright (c) 2004-2013 David Heinemeier Hansson
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
# a copy of this software and associated documentation files (the
|
@@ -21,26 +21,24 @@
|
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
#++
|
23
23
|
|
24
|
-
actionpack_path = File.expand_path('../../../actionpack/lib', __FILE__)
|
25
|
-
$:.unshift(actionpack_path) if File.directory?(actionpack_path) && !$:.include?(actionpack_path)
|
26
|
-
|
27
24
|
require 'abstract_controller'
|
28
25
|
require 'action_view'
|
29
26
|
require 'action_mailer/version'
|
30
27
|
|
31
28
|
# Common Active Support usage in Action Mailer
|
29
|
+
require 'active_support/rails'
|
32
30
|
require 'active_support/core_ext/class'
|
33
|
-
require 'active_support/core_ext/object/blank'
|
34
|
-
require 'active_support/core_ext/array/uniq_by'
|
35
31
|
require 'active_support/core_ext/module/attr_internal'
|
36
|
-
require 'active_support/core_ext/module/delegation'
|
37
32
|
require 'active_support/core_ext/string/inflections'
|
38
33
|
require 'active_support/lazy_load_hooks'
|
39
34
|
|
40
35
|
module ActionMailer
|
41
36
|
extend ::ActiveSupport::Autoload
|
42
37
|
|
43
|
-
|
38
|
+
eager_autoload do
|
39
|
+
autoload :Collector
|
40
|
+
end
|
41
|
+
|
44
42
|
autoload :Base
|
45
43
|
autoload :DeliveryMethods
|
46
44
|
autoload :MailHelper
|
data/lib/action_mailer/base.rb
CHANGED
@@ -1,14 +1,11 @@
|
|
1
1
|
require 'mail'
|
2
2
|
require 'action_mailer/collector'
|
3
|
-
require 'active_support/core_ext/array/wrap'
|
4
|
-
require 'active_support/core_ext/object/blank'
|
5
|
-
require 'active_support/core_ext/proc'
|
6
3
|
require 'active_support/core_ext/string/inflections'
|
7
4
|
require 'active_support/core_ext/hash/except'
|
8
5
|
require 'active_support/core_ext/module/anonymous'
|
9
6
|
require 'action_mailer/log_subscriber'
|
10
7
|
|
11
|
-
module ActionMailer
|
8
|
+
module ActionMailer
|
12
9
|
# Action Mailer allows you to send email from your application using a mailer model and views.
|
13
10
|
#
|
14
11
|
# = Mailer Models
|
@@ -17,20 +14,18 @@ module ActionMailer #:nodoc:
|
|
17
14
|
#
|
18
15
|
# $ rails generate mailer Notifier
|
19
16
|
#
|
20
|
-
# The generated model inherits from <tt>ActionMailer::Base</tt>.
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
# Examples:
|
17
|
+
# The generated model inherits from <tt>ActionMailer::Base</tt>. A mailer model defines methods
|
18
|
+
# used to generate an email message. In these methods, you can setup variables to be used in
|
19
|
+
# the mailer views, options on the mail itself such as the <tt>:from</tt> address, and attachments.
|
25
20
|
#
|
26
21
|
# class Notifier < ActionMailer::Base
|
27
|
-
# default :
|
28
|
-
#
|
22
|
+
# default from: 'no-reply@example.com',
|
23
|
+
# return_path: 'system@example.com'
|
29
24
|
#
|
30
25
|
# def welcome(recipient)
|
31
26
|
# @account = recipient
|
32
|
-
# mail(:
|
33
|
-
# :
|
27
|
+
# mail(to: recipient.email_address_with_name,
|
28
|
+
# bcc: ["bcc@example.com", "Order Watcher <watcher@example.com>"])
|
34
29
|
# end
|
35
30
|
# end
|
36
31
|
#
|
@@ -63,21 +58,21 @@ module ActionMailer #:nodoc:
|
|
63
58
|
#
|
64
59
|
# If you want to explicitly render only certain templates, pass a block:
|
65
60
|
#
|
66
|
-
# mail(:
|
61
|
+
# mail(to: user.email) do |format|
|
67
62
|
# format.text
|
68
63
|
# format.html
|
69
64
|
# end
|
70
65
|
#
|
71
66
|
# The block syntax is also useful in providing information specific to a part:
|
72
67
|
#
|
73
|
-
# mail(:
|
74
|
-
# format.text(:
|
68
|
+
# mail(to: user.email) do |format|
|
69
|
+
# format.text(content_transfer_encoding: "base64")
|
75
70
|
# format.html
|
76
71
|
# end
|
77
72
|
#
|
78
73
|
# Or even to render a special view:
|
79
74
|
#
|
80
|
-
# mail(:
|
75
|
+
# mail(to: user.email) do |format|
|
81
76
|
# format.text
|
82
77
|
# format.html { render "some_other_template" }
|
83
78
|
# end
|
@@ -101,12 +96,12 @@ module ActionMailer #:nodoc:
|
|
101
96
|
# You can even use Action Pack helpers in these views. For example:
|
102
97
|
#
|
103
98
|
# You got a new note!
|
104
|
-
# <%= truncate(@note.body, :
|
99
|
+
# <%= truncate(@note.body, length: 25) %>
|
105
100
|
#
|
106
101
|
# If you need to access the subject, from or the recipients in the view, you can do that through message object:
|
107
102
|
#
|
108
103
|
# You got a new note from <%= message.from %>!
|
109
|
-
# <%= truncate(@note.body, :
|
104
|
+
# <%= truncate(@note.body, length: 25) %>
|
110
105
|
#
|
111
106
|
#
|
112
107
|
# = Generating URLs
|
@@ -117,11 +112,11 @@ module ActionMailer #:nodoc:
|
|
117
112
|
#
|
118
113
|
# When using <tt>url_for</tt> you'll need to provide the <tt>:host</tt>, <tt>:controller</tt>, and <tt>:action</tt>:
|
119
114
|
#
|
120
|
-
# <%= url_for(:
|
115
|
+
# <%= url_for(host: "example.com", controller: "welcome", action: "greeting") %>
|
121
116
|
#
|
122
117
|
# When using named routes you only need to supply the <tt>:host</tt>:
|
123
118
|
#
|
124
|
-
# <%= users_url(:
|
119
|
+
# <%= users_url(host: "example.com") %>
|
125
120
|
#
|
126
121
|
# You should use the <tt>named_route_url</tt> style (which generates absolute URLs) and avoid using the
|
127
122
|
# <tt>named_route_path</tt> style (which generates relative URLs), since clients reading the mail will
|
@@ -130,12 +125,12 @@ module ActionMailer #:nodoc:
|
|
130
125
|
# It is also possible to set a default host that will be used in all mailers by setting the <tt>:host</tt>
|
131
126
|
# option as a configuration option in <tt>config/application.rb</tt>:
|
132
127
|
#
|
133
|
-
# config.action_mailer.default_url_options = { :
|
128
|
+
# config.action_mailer.default_url_options = { host: "example.com" }
|
134
129
|
#
|
135
130
|
# When you decide to set a default <tt>:host</tt> for your mailers, then you need to make sure to use the
|
136
|
-
# <tt
|
131
|
+
# <tt>only_path: false</tt> option when using <tt>url_for</tt>. Since the <tt>url_for</tt> view helper
|
137
132
|
# will generate relative URLs by default when a <tt>:host</tt> option isn't explicitly provided, passing
|
138
|
-
# <tt
|
133
|
+
# <tt>only_path: false</tt> will ensure that absolute URLs are generated.
|
139
134
|
#
|
140
135
|
# = Sending mail
|
141
136
|
#
|
@@ -176,7 +171,7 @@ module ActionMailer #:nodoc:
|
|
176
171
|
# class ApplicationMailer < ActionMailer::Base
|
177
172
|
# def welcome(recipient)
|
178
173
|
# attachments['free_book.pdf'] = File.read('path/to/file.pdf')
|
179
|
-
# mail(:
|
174
|
+
# mail(to: recipient, subject: "New account information")
|
180
175
|
# end
|
181
176
|
# end
|
182
177
|
#
|
@@ -186,6 +181,16 @@ module ActionMailer #:nodoc:
|
|
186
181
|
# and the second being a <tt>application/pdf</tt> with a Base64 encoded copy of the file.pdf book
|
187
182
|
# with the filename +free_book.pdf+.
|
188
183
|
#
|
184
|
+
# If you need to send attachments with no content, you need to create an empty view for it,
|
185
|
+
# or add an empty body parameter like this:
|
186
|
+
#
|
187
|
+
# class ApplicationMailer < ActionMailer::Base
|
188
|
+
# def welcome(recipient)
|
189
|
+
# attachments['free_book.pdf'] = File.read('path/to/file.pdf')
|
190
|
+
# mail(to: recipient, subject: "New account information", body: "")
|
191
|
+
# end
|
192
|
+
# end
|
193
|
+
#
|
189
194
|
# = Inline Attachments
|
190
195
|
#
|
191
196
|
# You can also specify that a file should be displayed inline with other HTML. This is useful
|
@@ -194,7 +199,7 @@ module ActionMailer #:nodoc:
|
|
194
199
|
# class ApplicationMailer < ActionMailer::Base
|
195
200
|
# def welcome(recipient)
|
196
201
|
# attachments.inline['photo.png'] = File.read('path/to/photo.png')
|
197
|
-
# mail(:
|
202
|
+
# mail(to: recipient, subject: "Here is what we look like")
|
198
203
|
# end
|
199
204
|
# end
|
200
205
|
#
|
@@ -210,7 +215,7 @@ module ActionMailer #:nodoc:
|
|
210
215
|
#
|
211
216
|
# <h1>Please Don't Cringe</h1>
|
212
217
|
#
|
213
|
-
# <%= image_tag attachments['photo.png'].url, :
|
218
|
+
# <%= image_tag attachments['photo.png'].url, alt: 'Our Photo', class: 'photo' -%>
|
214
219
|
#
|
215
220
|
# = Observing and Intercepting Mails
|
216
221
|
#
|
@@ -231,16 +236,16 @@ module ActionMailer #:nodoc:
|
|
231
236
|
# default method inside the class definition:
|
232
237
|
#
|
233
238
|
# class Notifier < ActionMailer::Base
|
234
|
-
# default :
|
239
|
+
# default sender: 'system@example.com'
|
235
240
|
# end
|
236
241
|
#
|
237
242
|
# You can pass in any header value that a <tt>Mail::Message</tt> accepts. Out of the box,
|
238
243
|
# <tt>ActionMailer::Base</tt> sets the following:
|
239
244
|
#
|
240
|
-
# * <tt
|
241
|
-
# * <tt
|
242
|
-
# * <tt
|
243
|
-
# * <tt
|
245
|
+
# * <tt>mime_version: "1.0"</tt>
|
246
|
+
# * <tt>charset: "UTF-8",</tt>
|
247
|
+
# * <tt>content_type: "text/plain",</tt>
|
248
|
+
# * <tt>parts_order: [ "text/plain", "text/enriched", "text/html" ]</tt>
|
244
249
|
#
|
245
250
|
# <tt>parts_order</tt> and <tt>charset</tt> are not actually valid <tt>Mail::Message</tt> header fields,
|
246
251
|
# but Action Mailer translates them appropriately and sets the correct values.
|
@@ -250,7 +255,7 @@ module ActionMailer #:nodoc:
|
|
250
255
|
#
|
251
256
|
# class Notifier < ActionMailer::Base
|
252
257
|
# default 'Content-Transfer-Encoding' => '7bit',
|
253
|
-
# :
|
258
|
+
# content_description: 'This is a description'
|
254
259
|
# end
|
255
260
|
#
|
256
261
|
# Finally, Action Mailer also supports passing <tt>Proc</tt> objects into the default hash, so you
|
@@ -270,12 +275,44 @@ module ActionMailer #:nodoc:
|
|
270
275
|
# set something in the defaults using a proc, and then set the same thing inside of your
|
271
276
|
# mailer method, it will get over written by the mailer method.
|
272
277
|
#
|
278
|
+
# It is also possible to set these default options that will be used in all mailers through
|
279
|
+
# the <tt>default_options=</tt> configuration in <tt>config/application.rb</tt>:
|
280
|
+
#
|
281
|
+
# config.action_mailer.default_options = { from: "no-reply@example.org" }
|
282
|
+
#
|
283
|
+
# = Callbacks
|
284
|
+
#
|
285
|
+
# You can specify callbacks using before_action and after_action for configuring your messages.
|
286
|
+
# This may be useful, for example, when you want to add default inline attachments for all
|
287
|
+
# messages sent out by a certain mailer class:
|
288
|
+
#
|
289
|
+
# class Notifier < ActionMailer::Base
|
290
|
+
# before_action :add_inline_attachment!
|
291
|
+
#
|
292
|
+
# def welcome
|
293
|
+
# mail
|
294
|
+
# end
|
295
|
+
#
|
296
|
+
# private
|
297
|
+
#
|
298
|
+
# def add_inline_attachment!
|
299
|
+
# attachments.inline["footer.jpg"] = File.read('/path/to/filename.jpg')
|
300
|
+
# end
|
301
|
+
# end
|
302
|
+
#
|
303
|
+
# Callbacks in ActionMailer are implemented using AbstractController::Callbacks, so you
|
304
|
+
# can define and configure callbacks in the same manner that you would use callbacks in
|
305
|
+
# classes that inherit from ActionController::Base.
|
306
|
+
#
|
307
|
+
# Note that unless you have a specific reason to do so, you should prefer using before_action
|
308
|
+
# rather than after_action in your ActionMailer classes so that headers are parsed properly.
|
309
|
+
#
|
273
310
|
# = Configuration options
|
274
311
|
#
|
275
312
|
# These options are specified on the class level, like
|
276
313
|
# <tt>ActionMailer::Base.raise_delivery_errors = true</tt>
|
277
314
|
#
|
278
|
-
# * <tt>
|
315
|
+
# * <tt>default_options</tt> - You can pass this in at a class level as well as within the class itself as
|
279
316
|
# per the above section.
|
280
317
|
#
|
281
318
|
# * <tt>logger</tt> - the logger is used for generating information on the mailing run if available.
|
@@ -313,7 +350,7 @@ module ActionMailer #:nodoc:
|
|
313
350
|
#
|
314
351
|
# * <tt>delivery_method</tt> - Defines a delivery method. Possible values are <tt>:smtp</tt> (default),
|
315
352
|
# <tt>:sendmail</tt>, <tt>:test</tt>, and <tt>:file</tt>. Or you may provide a custom delivery method
|
316
|
-
# object
|
353
|
+
# object e.g. MyOwnDeliveryMethodClass. See the Mail gem documentation on the interface you need to
|
317
354
|
# implement for a custom delivery agent.
|
318
355
|
#
|
319
356
|
# * <tt>perform_deliveries</tt> - Determines whether emails are actually sent from Action Mailer when you
|
@@ -322,7 +359,6 @@ module ActionMailer #:nodoc:
|
|
322
359
|
#
|
323
360
|
# * <tt>deliveries</tt> - Keeps an array of all the emails sent out through the Action Mailer with
|
324
361
|
# <tt>delivery_method :test</tt>. Most useful for unit and functional testing.
|
325
|
-
#
|
326
362
|
class Base < AbstractController::Base
|
327
363
|
include DeliveryMethods
|
328
364
|
abstract!
|
@@ -333,19 +369,20 @@ module ActionMailer #:nodoc:
|
|
333
369
|
include AbstractController::Helpers
|
334
370
|
include AbstractController::Translation
|
335
371
|
include AbstractController::AssetPaths
|
372
|
+
include AbstractController::Callbacks
|
336
373
|
|
337
|
-
self.protected_instance_variables =
|
374
|
+
self.protected_instance_variables = [:@_action_has_layout]
|
338
375
|
|
339
|
-
helper
|
376
|
+
helper ActionMailer::MailHelper
|
340
377
|
|
341
378
|
private_class_method :new #:nodoc:
|
342
379
|
|
343
380
|
class_attribute :default_params
|
344
381
|
self.default_params = {
|
345
|
-
:
|
346
|
-
:
|
347
|
-
:
|
348
|
-
:
|
382
|
+
mime_version: "1.0",
|
383
|
+
charset: "UTF-8",
|
384
|
+
content_type: "text/plain",
|
385
|
+
parts_order: [ "text/plain", "text/enriched", "text/html" ]
|
349
386
|
}.freeze
|
350
387
|
|
351
388
|
class << self
|
@@ -385,6 +422,10 @@ module ActionMailer #:nodoc:
|
|
385
422
|
self.default_params = default_params.merge(value).freeze if value
|
386
423
|
default_params
|
387
424
|
end
|
425
|
+
# Allows to set defaults through app configuration:
|
426
|
+
#
|
427
|
+
# config.action_mailer.default_options = { from: "no-reply@example.org" }
|
428
|
+
alias :default_options= :default
|
388
429
|
|
389
430
|
# Receives a raw email, parses it into an email object, decodes it,
|
390
431
|
# instantiates a new mailer, and passes the email object to the mailer
|
@@ -411,7 +452,7 @@ module ActionMailer #:nodoc:
|
|
411
452
|
# and passing a Mail::Message will do nothing except tell the logger you sent the email.
|
412
453
|
def deliver_mail(mail) #:nodoc:
|
413
454
|
ActiveSupport::Notifications.instrument("deliver.action_mailer") do |payload|
|
414
|
-
|
455
|
+
set_payload_for_mail(payload, mail)
|
415
456
|
yield # Let Mail do the delivery actions
|
416
457
|
end
|
417
458
|
end
|
@@ -434,9 +475,12 @@ module ActionMailer #:nodoc:
|
|
434
475
|
payload[:mail] = mail.encoded
|
435
476
|
end
|
436
477
|
|
437
|
-
def method_missing(
|
438
|
-
|
439
|
-
|
478
|
+
def method_missing(method_name, *args)
|
479
|
+
if respond_to?(method_name)
|
480
|
+
new(method_name, *args).message
|
481
|
+
else
|
482
|
+
super
|
483
|
+
end
|
440
484
|
end
|
441
485
|
end
|
442
486
|
|
@@ -448,7 +492,7 @@ module ActionMailer #:nodoc:
|
|
448
492
|
# method, for instance).
|
449
493
|
def initialize(method_name=nil, *args)
|
450
494
|
super()
|
451
|
-
@
|
495
|
+
@_mail_was_called = false
|
452
496
|
@_message = Mail.new
|
453
497
|
process(method_name, *args) if method_name
|
454
498
|
end
|
@@ -457,7 +501,7 @@ module ActionMailer #:nodoc:
|
|
457
501
|
lookup_context.skip_default_locale!
|
458
502
|
|
459
503
|
super
|
460
|
-
@_message = NullMail.new unless @
|
504
|
+
@_message = NullMail.new unless @_mail_was_called
|
461
505
|
end
|
462
506
|
|
463
507
|
class NullMail #:nodoc:
|
@@ -472,7 +516,7 @@ module ActionMailer #:nodoc:
|
|
472
516
|
self.class.mailer_name
|
473
517
|
end
|
474
518
|
|
475
|
-
# Allows you to pass random and unusual headers to the new
|
519
|
+
# Allows you to pass random and unusual headers to the new <tt>Mail::Message</tt> object
|
476
520
|
# which will add them to itself.
|
477
521
|
#
|
478
522
|
# headers['X-Special-Domain-Specific-Header'] = "SecretValue"
|
@@ -483,10 +527,10 @@ module ActionMailer #:nodoc:
|
|
483
527
|
# headers 'X-Special-Domain-Specific-Header' => "SecretValue",
|
484
528
|
# 'In-Reply-To' => incoming.message_id
|
485
529
|
#
|
486
|
-
# The resulting Mail::Message will have the following in
|
530
|
+
# The resulting Mail::Message will have the following in its header:
|
487
531
|
#
|
488
532
|
# X-Special-Domain-Specific-Header: SecretValue
|
489
|
-
def headers(args=nil)
|
533
|
+
def headers(args = nil)
|
490
534
|
if args
|
491
535
|
@_message.headers(args)
|
492
536
|
else
|
@@ -504,17 +548,17 @@ module ActionMailer #:nodoc:
|
|
504
548
|
#
|
505
549
|
# You can also specify overrides if you want by passing a hash instead of a string:
|
506
550
|
#
|
507
|
-
# mail.attachments['filename.jpg'] = {:
|
508
|
-
# :
|
551
|
+
# mail.attachments['filename.jpg'] = {mime_type: 'application/x-gzip',
|
552
|
+
# content: File.read('/path/to/filename.jpg')}
|
509
553
|
#
|
510
554
|
# If you want to use a different encoding than Base64, you can pass an encoding in,
|
511
555
|
# but then it is up to you to pass in the content pre-encoded, and don't expect
|
512
556
|
# Mail to know how to decode this data:
|
513
557
|
#
|
514
558
|
# file_content = SpecialEncode(File.read('/path/to/filename.jpg'))
|
515
|
-
# mail.attachments['filename.jpg'] = {:
|
516
|
-
# :
|
517
|
-
# :
|
559
|
+
# mail.attachments['filename.jpg'] = {mime_type: 'application/x-gzip',
|
560
|
+
# encoding: 'SpecialEncoding',
|
561
|
+
# content: file_content }
|
518
562
|
#
|
519
563
|
# You can also search for specific attachments:
|
520
564
|
#
|
@@ -552,9 +596,9 @@ module ActionMailer #:nodoc:
|
|
552
596
|
# class method:
|
553
597
|
#
|
554
598
|
# class Notifier < ActionMailer::Base
|
555
|
-
# self.default :
|
556
|
-
# :
|
557
|
-
# :
|
599
|
+
# self.default from: 'no-reply@test.lindsaar.net',
|
600
|
+
# bcc: 'email_logger@test.lindsaar.net',
|
601
|
+
# reply_to: 'bounces@test.lindsaar.net'
|
558
602
|
# end
|
559
603
|
#
|
560
604
|
# If you need other headers not listed above, you can either pass them in
|
@@ -576,32 +620,34 @@ module ActionMailer #:nodoc:
|
|
576
620
|
# For example:
|
577
621
|
#
|
578
622
|
# class Notifier < ActionMailer::Base
|
579
|
-
# default :
|
623
|
+
# default from: 'no-reply@test.lindsaar.net',
|
580
624
|
#
|
581
625
|
# def welcome
|
582
|
-
# mail(:
|
626
|
+
# mail(to: 'mikel@test.lindsaar.net')
|
583
627
|
# end
|
584
628
|
# end
|
585
629
|
#
|
586
|
-
# Will look for all templates at "app/views/notifier" with name "welcome".
|
587
|
-
#
|
630
|
+
# Will look for all templates at "app/views/notifier" with name "welcome".
|
631
|
+
# If no welcome template exists, it will raise an ActionView::MissingTemplate error.
|
632
|
+
#
|
633
|
+
# However, those can be customized:
|
588
634
|
#
|
589
|
-
# mail(:
|
635
|
+
# mail(template_path: 'notifications', template_name: 'another')
|
590
636
|
#
|
591
637
|
# And now it will look for all templates at "app/views/notifications" with name "another".
|
592
638
|
#
|
593
639
|
# If you do pass a block, you can render specific templates of your choice:
|
594
640
|
#
|
595
|
-
# mail(:
|
641
|
+
# mail(to: 'mikel@test.lindsaar.net') do |format|
|
596
642
|
# format.text
|
597
643
|
# format.html
|
598
644
|
# end
|
599
645
|
#
|
600
646
|
# You can even render text directly without using a template:
|
601
647
|
#
|
602
|
-
# mail(:
|
603
|
-
# format.text { render :
|
604
|
-
# format.html { render :
|
648
|
+
# mail(to: 'mikel@test.lindsaar.net') do |format|
|
649
|
+
# format.text { render text: "Hello Mikel!" }
|
650
|
+
# format.html { render text: "<h1>Hello Mikel!</h1>" }
|
605
651
|
# end
|
606
652
|
#
|
607
653
|
# Which will render a <tt>multipart/alternative</tt> email with <tt>text/plain</tt> and
|
@@ -609,25 +655,22 @@ module ActionMailer #:nodoc:
|
|
609
655
|
#
|
610
656
|
# The block syntax also allows you to customize the part headers if desired:
|
611
657
|
#
|
612
|
-
# mail(:
|
613
|
-
# format.text(:
|
658
|
+
# mail(to: 'mikel@test.lindsaar.net') do |format|
|
659
|
+
# format.text(content_transfer_encoding: "base64")
|
614
660
|
# format.html
|
615
661
|
# end
|
616
662
|
#
|
617
|
-
def mail(headers={}, &block)
|
618
|
-
|
619
|
-
# On master this flag was renamed to `@_mail_was_called`.
|
620
|
-
# On master there is only one API and this flag is no longer used as a guard.
|
621
|
-
@mail_was_called = true
|
663
|
+
def mail(headers = {}, &block)
|
664
|
+
@_mail_was_called = true
|
622
665
|
m = @_message
|
623
666
|
|
624
|
-
# At the beginning, do not consider class default for
|
667
|
+
# At the beginning, do not consider class default for content_type
|
625
668
|
content_type = headers[:content_type]
|
626
|
-
parts_order = headers[:parts_order]
|
627
669
|
|
628
670
|
# Call all the procs (if any)
|
629
|
-
|
630
|
-
|
671
|
+
class_default = self.class.default
|
672
|
+
default_values = class_default.merge(class_default) do |k,v|
|
673
|
+
v.respond_to?(:to_proc) ? instance_eval(&v) : v
|
631
674
|
end
|
632
675
|
|
633
676
|
# Handle defaults
|
@@ -638,14 +681,14 @@ module ActionMailer #:nodoc:
|
|
638
681
|
m.charset = charset = headers[:charset]
|
639
682
|
|
640
683
|
# Set configure delivery behavior
|
641
|
-
wrap_delivery_behavior!(headers.delete(:delivery_method))
|
684
|
+
wrap_delivery_behavior!(headers.delete(:delivery_method),headers.delete(:delivery_method_options))
|
642
685
|
|
643
686
|
# Assign all headers except parts_order, content_type and body
|
644
687
|
assignable = headers.except(:parts_order, :content_type, :body, :template_name, :template_path)
|
645
688
|
assignable.each { |k, v| m[k] = v }
|
646
689
|
|
647
690
|
# Render the templates and blocks
|
648
|
-
responses
|
691
|
+
responses = collect_responses(headers, &block)
|
649
692
|
create_parts_from_responses(m, responses)
|
650
693
|
|
651
694
|
# Setup content type, reapply charset and handle parts order
|
@@ -653,8 +696,7 @@ module ActionMailer #:nodoc:
|
|
653
696
|
m.charset = charset
|
654
697
|
|
655
698
|
if m.multipart?
|
656
|
-
|
657
|
-
m.body.set_sort_order(parts_order)
|
699
|
+
m.body.set_sort_order(headers[:parts_order])
|
658
700
|
m.body.sort_parts!
|
659
701
|
end
|
660
702
|
|
@@ -681,47 +723,51 @@ module ActionMailer #:nodoc:
|
|
681
723
|
end
|
682
724
|
end
|
683
725
|
|
684
|
-
# Translates the +subject+ using Rails I18n class under <tt>[
|
726
|
+
# Translates the +subject+ using Rails I18n class under <tt>[mailer_scope, action_name]</tt> scope.
|
685
727
|
# If it does not find a translation for the +subject+ under the specified scope it will default to a
|
686
728
|
# humanized version of the <tt>action_name</tt>.
|
687
|
-
|
688
|
-
|
689
|
-
|
729
|
+
# If the subject has interpolations, you can pass them through the +interpolations+ parameter.
|
730
|
+
def default_i18n_subject(interpolations = {})
|
731
|
+
mailer_scope = self.class.mailer_name.tr('/', '.')
|
732
|
+
I18n.t(:subject, interpolations.merge(scope: [mailer_scope, action_name], default: action_name.humanize))
|
690
733
|
end
|
691
734
|
|
692
|
-
def
|
693
|
-
responses
|
735
|
+
def collect_responses(headers) #:nodoc:
|
736
|
+
responses = []
|
694
737
|
|
695
738
|
if block_given?
|
696
739
|
collector = ActionMailer::Collector.new(lookup_context) { render(action_name) }
|
697
740
|
yield(collector)
|
698
|
-
|
699
|
-
responses = collector.responses
|
741
|
+
responses = collector.responses
|
700
742
|
elsif headers[:body]
|
701
743
|
responses << {
|
702
|
-
:
|
703
|
-
:
|
744
|
+
body: headers.delete(:body),
|
745
|
+
content_type: self.class.default[:content_type] || "text/plain"
|
704
746
|
}
|
705
747
|
else
|
706
748
|
templates_path = headers.delete(:template_path) || self.class.mailer_name
|
707
749
|
templates_name = headers.delete(:template_name) || action_name
|
708
750
|
|
709
|
-
each_template(templates_path, templates_name) do |template|
|
751
|
+
each_template(Array(templates_path), templates_name) do |template|
|
710
752
|
self.formats = template.formats
|
711
753
|
|
712
754
|
responses << {
|
713
|
-
:
|
714
|
-
:
|
755
|
+
body: render(template: template),
|
756
|
+
content_type: template.type.to_s
|
715
757
|
}
|
716
758
|
end
|
717
759
|
end
|
718
760
|
|
719
|
-
|
761
|
+
responses
|
720
762
|
end
|
721
763
|
|
722
764
|
def each_template(paths, name, &block) #:nodoc:
|
723
|
-
templates = lookup_context.find_all(name,
|
724
|
-
templates.
|
765
|
+
templates = lookup_context.find_all(name, paths)
|
766
|
+
if templates.empty?
|
767
|
+
raise ActionView::MissingTemplate.new(paths, name, paths, false, 'mailer')
|
768
|
+
else
|
769
|
+
templates.uniq { |t| t.formats }.each(&block)
|
770
|
+
end
|
725
771
|
end
|
726
772
|
|
727
773
|
def create_parts_from_responses(m, responses) #:nodoc:
|
@@ -746,4 +792,3 @@ module ActionMailer #:nodoc:
|
|
746
792
|
ActiveSupport.run_load_hooks(:action_mailer, self)
|
747
793
|
end
|
748
794
|
end
|
749
|
-
|