Skip to content
Newer
Older
100644 690 lines (644 sloc) 28.5 KB
616ebb8 @josevalim Remove unused code paths and require mail only when it's needed.
josevalim authored Dec 28, 2009
1 require 'mail'
a288082 @mikel Adding :transfer_encoding -> :content_transfer_encoding as part of Tm…
mikel authored Dec 30, 2009
2 require 'action_mailer/tmail_compat'
c985a0e Add some tests to collector with templates and any.
José Valim and Mikel Lindsaar authored Jan 23, 2010
3 require 'action_mailer/collector'
41af6d9 @jeremy Use Array.wrap not Array()
jeremy authored Mar 17, 2010
4 require 'active_support/core_ext/array/wrap'
76f024a @fxn adds missing requires for Object#blank? and Object#present?
fxn authored Mar 28, 2010
5 require 'active_support/core_ext/object/blank'
a63caa4 Get tests to run (with failures) without old base around
Yehuda Katz + Carl Lerche authored Jun 15, 2009
6
c4590d5 @dhh Fixed docs
dhh authored Mar 28, 2006
7 module ActionMailer #:nodoc:
98dc582 @lifo Merge docrails.
lifo authored May 25, 2008
8 # Action Mailer allows you to send email from your application using a mailer model and views.
db045db @dhh Initial
dhh authored Nov 24, 2004
9 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
10 # = Mailer Models
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
11 #
98dc582 @lifo Merge docrails.
lifo authored May 25, 2008
12 # To use Action Mailer, you need to create a mailer model.
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
13 #
f44a0b1 @romdi fix usage examples and more to use new invocations
romdi authored Feb 6, 2010
14 # $ rails generate mailer Notifier
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
15 #
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
16 # The generated model inherits from ActionMailer::Base. Emails are defined by creating methods
17 # within the model which are then used to set variables to be used in the mail template, to
18 # change options on the mail, or to add attachments.
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
19 #
20 # Examples:
21 #
22 # class Notifier < ActionMailer::Base
452bb1e @jeremy Rename 'defaults' class method to 'default' to reflect that it's a de…
jeremy authored Jan 27, 2010
23 # default :from => 'no-reply@example.com',
24 # :return_path => 'system@example.com'
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
25 #
26 # def welcome(recipient)
27 # @account = recipient
6589976 Remove old files, add some information to docs and improve test suite.
José Valim and Mikel Lindsaar authored Jan 26, 2010
28 # mail(:to => recipient.email_address_with_name,
29 # :bcc => ["bcc@example.com", "Order Watcher <watcher@example.com>"])
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
30 # end
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
31 # end
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
32 #
33 # Within the mailer method, you have access to the following methods:
34 #
35 # * <tt>attachments[]=</tt> - Allows you to add attachments to your email in an intuitive
36 # manner; <tt>attachments['filename.png'] = File.read('path/to/filename.png')</tt>
6589976 Remove old files, add some information to docs and improve test suite.
José Valim and Mikel Lindsaar authored Jan 26, 2010
37 #
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
38 # * <tt>headers[]=</tt> - Allows you to specify any header field in your email such
39 # as <tt>headers['X-No-Spam'] = 'True'</tt>. Note, while most fields (like <tt>To:</tt>
40 # <tt>From:</tt> can only appear once in an email header, other fields like <tt>X-Anything</tt>
41 # can appear multiple times. If you want to change a field that can appear multiple times,
42 # you need to set it to nil first so that Mail knows you are replacing it, not adding
43 # another field of the same name.)
6589976 Remove old files, add some information to docs and improve test suite.
José Valim and Mikel Lindsaar authored Jan 26, 2010
44 #
9520166 @mikel Fixed up being able to pass random headers in with headers, or mail. …
mikel authored Jan 27, 2010
45 # * <tt>headers(hash)</tt> - Allows you to specify multiple headers in your email such
46 # as <tt>headers({'X-No-Spam' => 'True', 'In-Reply-To' => '1234@message.id'})</tt>
47 #
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
48 # * <tt>mail</tt> - Allows you to specify your email to send.
49 #
9520166 @mikel Fixed up being able to pass random headers in with headers, or mail. …
mikel authored Jan 26, 2010
50 # The hash passed to the mail method allows you to specify any header that a Mail::Message
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
51 # will accept (any valid Email header including optional fields).
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
52 #
53 # The mail method, if not passed a block, will inspect your views and send all the views with
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
54 # the same name as the method, so the above action would send the +welcome.text.plain.erb+ view
55 # file as well as the +welcome.text.html.erb+ view file in a +multipart/alternative+ email.
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
56 #
57 # If you want to explicitly render only certain templates, pass a block:
58 #
59 # mail(:to => user.emai) do |format|
60 # format.text
61 # format.html
62 # end
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
63 #
6589976 Remove old files, add some information to docs and improve test suite.
José Valim and Mikel Lindsaar authored Jan 26, 2010
64 # The block syntax is useful if also need to specify information specific to a part:
65 #
66 # mail(:to => user.emai) do |format|
67 # format.text(:content_transfer_encoding => "base64")
68 # format.html
69 # end
70 #
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
71 # Or even to render a special view:
6589976 Remove old files, add some information to docs and improve test suite.
José Valim and Mikel Lindsaar authored Jan 26, 2010
72 #
73 # mail(:to => user.emai) do |format|
74 # format.text
75 # format.html { render "some_other_template" }
76 # end
77 #
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
78 # = Mailer views
79 #
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
80 # Like Action Controller, each mailer class has a corresponding view directory in which each
81 # method of the class looks for a template with its name.
82 #
83 # To define a template to be used with a mailing, create an <tt>.erb</tt> file with the same
84 # name as the method in your mailer model. For example, in the mailer defined above, the template at
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
85 # <tt>app/views/notifier/signup_notification.text.plain.erb</tt> would be used to generate the email.
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
86 #
87 # Variables defined in the model are accessible as instance variables in the view.
88 #
89 # Emails by default are sent in plain text, so a sample view for our model example might look like this:
90 #
91 # Hi <%= @account.name %>,
92 # Thanks for joining our service! Please check back often.
93 #
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
94 # You can even use Action Pack helpers in these views. For example:
95 #
96 # You got a new note!
ee70d1b @josevalim adv_attr_accessors in ActionMailer are not sent to the views, use the…
josevalim authored Dec 25, 2009
97 # <%= truncate(@note.body, 25) %>
98 #
6589976 Remove old files, add some information to docs and improve test suite.
José Valim and Mikel Lindsaar authored Jan 26, 2010
99 # If you need to access the subject, from or the recipients in the view, you can do that through message object:
ee70d1b @josevalim adv_attr_accessors in ActionMailer are not sent to the views, use the…
josevalim authored Dec 25, 2009
100 #
6589976 Remove old files, add some information to docs and improve test suite.
José Valim and Mikel Lindsaar authored Jan 26, 2010
101 # You got a new note from <%= message.from %>!
ee70d1b @josevalim adv_attr_accessors in ActionMailer are not sent to the views, use the…
josevalim authored Dec 25, 2009
102 # <%= truncate(@note.body, 25) %>
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
103 #
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
104 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored Apr 21, 2008
105 # = Generating URLs
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
106 #
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
107 # URLs can be generated in mailer views using <tt>url_for</tt> or named routes. Unlike controllers from
108 # Action Pack, the mailer instance doesn't have any context about the incoming request, so you'll need
109 # to provide all of the details needed to generate a URL.
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
110 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored Apr 21, 2008
111 # When using <tt>url_for</tt> you'll need to provide the <tt>:host</tt>, <tt>:controller</tt>, and <tt>:action</tt>:
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
112 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored Apr 21, 2008
113 # <%= url_for(:host => "example.com", :controller => "welcome", :action => "greeting") %>
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
114 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored Apr 21, 2008
115 # When using named routes you only need to supply the <tt>:host</tt>:
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
116 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored Apr 21, 2008
117 # <%= users_url(:host => "example.com") %>
118 #
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
119 # You will want to avoid using the <tt>name_of_route_path</tt> form of named routes because it doesn't
120 # make sense to generate relative URLs in email messages.
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored Apr 21, 2008
121 #
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
122 # It is also possible to set a default host that will be used in all mailers by setting the <tt>:host</tt>
123 # option in the <tt>ActionMailer::Base.default_url_options</tt> hash as follows:
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored Apr 21, 2008
124 #
125 # ActionMailer::Base.default_url_options[:host] = "example.com"
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
126 #
dc4eec1 @lifo Merge docrails:
lifo authored May 9, 2008
127 # This can also be set as a configuration option in <tt>config/environment.rb</tt>:
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored Apr 21, 2008
128 #
129 # config.action_mailer.default_url_options = { :host => "example.com" }
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
130 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored Apr 21, 2008
131 # If you do decide to set a default <tt>:host</tt> for your mailers you will want to use the
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
132 # <tt>:only_path => false</tt> option when using <tt>url_for</tt>. This will ensure that absolute URLs are
133 # generated because the <tt>url_for</tt> view helper will, by default, generate relative URLs when a
134 # <tt>:host</tt> option isn't explicitly provided.
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
135 #
136 # = Sending mail
137 #
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
138 # Once a mailer action and template are defined, you can deliver your message or create it and save it
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
139 # for delivery later:
140 #
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
141 # Notifier.welcome(david).deliver # sends the email
142 # mail = Notifier.welcome(david) # => a Mail::Message object
143 # mail.deliver # sends the email
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
144 #
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
145 # You never instantiate your mailer class. Rather, you just call the method you defined on the class itself.
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
146 #
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
147 # = Multipart Emails
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
148 #
98dc582 @lifo Merge docrails.
lifo authored May 25, 2008
149 # Multipart messages can also be used implicitly because Action Mailer will automatically
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
150 # detect and use multipart templates, where each template is named after the name of the action, followed
151 # by the content type. Each such detected template will be added as separate part to the message.
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
152 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
153 # For example, if the following templates existed:
21187c0 @dhh Apply the rest of Chads patch
dhh authored Feb 21, 2007
154 # * signup_notification.text.plain.erb
155 # * signup_notification.text.html.erb
156 # * signup_notification.text.xml.builder
6589976 Remove old files, add some information to docs and improve test suite.
José Valim and Mikel Lindsaar authored Jan 26, 2010
157 # * signup_notification.text.yaml.erb
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
158 #
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
159 # Each would be rendered and added as a separate part to the message, with the corresponding content
160 # type. The content type for the entire message is automatically set to <tt>multipart/alternative</tt>,
161 # which indicates that the email contains multiple different representations of the same email
162 # body. The same instance variables defined in the action are passed to all email templates.
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored May 29, 2005
163 #
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored May 16, 2008
164 # Implicit template rendering is not performed if any attachments or parts have been added to the email.
165 # This means that you'll have to manually add each part to the email and set the content type of the email
166 # to <tt>multipart/alternative</tt>.
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
167 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
168 # = Attachments
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
169 #
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
170 # You can see above how to make a multipart HTML / Text email, to send attachments is just
171 # as easy:
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
172 #
173 # class ApplicationMailer < ActionMailer::Base
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
174 # def welcome(recipient)
175 # attachments['free_book.pdf'] = { :data => File.read('path/to/file.pdf') }
176 # mail(:to => recipient, :subject => "New account information")
db045db @dhh Initial
dhh authored Nov 24, 2004
177 # end
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
178 # end
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
179 #
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
180 # Which will (if it had both a <tt>welcome.text.plain.erb</tt> and <tt>welcome.text.html.erb</tt>
181 # tempalte in the view directory), send a complete <tt>multipart/mixed</tt> email with two parts,
182 # the first part being a <tt>multipart/alternative</tt> with the text and HTML email parts inside,
183 # and the second being a <tt>application/pdf</tt> with a Base64 encoded copy of the file.pdf book
184 # with the filename +free_book.pdf+.
c927aa0 @dhh Updated documentation
dhh authored Dec 16, 2004
185 #
cefc136 @mikel Adding options to register observers and interceptors through ActionM…
mikel authored Feb 22, 2010
186 # = Observing and Intercepting Mails
187 #
188 # ActionMailer provides hooks into the Mail observer and interceptor methods. These allow you to
189 # register objects that are called during the mail delivery life cycle.
190 #
191 # An observer object must implement the <tt>:delivered_email(message)</tt> method which will be
192 # called once for every email sent after the email has been sent.
193 #
194 # An interceptor object must implement the <tt>:delivering_email(message)</tt> method which will be
195 # called before the email is sent, allowing you to make modifications to the email before it hits
196 # the delivery agents. Your object should make and needed modifications directly to the passed
197 # in Mail::Message instance.
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
198 #
fb30feb @mikel Adding more docs to ActionMailer
mikel authored May 2, 2010
199 # = Default Hash
200 #
201 # ActionMailer provides some intelligent defaults for your emails, these are usually specified in a
202 # default method inside the class definition:
203 #
204 # class Notifier < ActionMailer::Base
205 # default :sender => 'system@example.com'
206 # end
207 #
208 # You can pass in any header value that a <tt>Mail::Message</tt>, out of the box, <tt>ActionMailer::Base</tt>
209 # sets the following:
210 #
211 # * <tt>:mime_version => "1.0"</tt>
212 # * <tt>:charset => "UTF-8",</tt>
213 # * <tt>:content_type => "text/plain",</tt>
214 # * <tt>:parts_order => [ "text/plain", "text/enriched", "text/html" ]</tt>
215 #
216 # <tt>parts_order</tt> and <tt>charset</tt> are not actually valid <tt>Mail::Message</tt> header fields,
217 # but ActionMailer translates them appropriately and sets the correct values.
218 #
219 # As you can pass in any header, you need to either quote the header as a string, or pass it in as
220 # an underscorised symbol, so the following will work:
221 #
222 # class Notifier < ActionMailer::Base
223 # default 'Content-Transfer-Encoding' => '7bit',
224 # :content_description => 'This is a description'
225 # end
226 #
227 # Finally, ActionMailer also supports passing <tt>Proc</tt> objects into the default hash, so you
228 # can define methods that evaluate as the message is being generated:
229 #
230 # class Notifier < ActionMailer::Base
231 # default 'X-Special-Header' => Proc.new { my_method }
232 #
233 # private
234 #
235 # def my_method
236 # 'some complex call'
237 # end
238 # end
239 #
240 # Note that the proc is evaluated right at the start of the mail message generation, so if you
241 # set something in the defaults using a proc, and then set the same thing inside of your
242 # mailer method, it will get over written by the mailer method.
243 #
c927aa0 @dhh Updated documentation
dhh authored Dec 16, 2004
244 # = Configuration options
245 #
fb30feb @mikel Adding more docs to ActionMailer
mikel authored May 2, 2010
246 # These options are specified on the class level, like
247 # <tt>ActionMailer::Base.template_root = "/my/templates"</tt>
c927aa0 @dhh Updated documentation
dhh authored Dec 16, 2004
248 #
fb30feb @mikel Adding more docs to ActionMailer
mikel authored May 2, 2010
249 # * <tt>default</tt> - You can pass this in at a class level as well as within the class itself as
250 # per the above section.
251 #
c927aa0 @dhh Updated documentation
dhh authored Dec 16, 2004
252 # * <tt>logger</tt> - the logger is used for generating information on the mailing run if available.
253 # Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers.
254 #
64092de @fxn Improve documentation coverage and markup
fxn authored May 2, 2008
255 # * <tt>smtp_settings</tt> - Allows detailed configuration for <tt>:smtp</tt> delivery method:
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
256 # * <tt>:address</tt> - Allows you to use a remote mail server. Just change it from its default
257 # "localhost" setting.
dc4eec1 @lifo Merge docrails:
lifo authored May 9, 2008
258 # * <tt>:port</tt> - On the off chance that your mail server doesn't run on port 25, you can change it.
259 # * <tt>:domain</tt> - If you need to specify a HELO domain, you can do it here.
260 # * <tt>:user_name</tt> - If your mail server requires authentication, set the username in this setting.
261 # * <tt>:password</tt> - If your mail server requires authentication, set the password in this setting.
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
262 # * <tt>:authentication</tt> - If your mail server requires authentication, you need to specify the
263 # authentication type here.
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored May 16, 2008
264 # This is a symbol and one of <tt>:plain</tt>, <tt>:login</tt>, <tt>:cram_md5</tt>.
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
265 # * <tt>:enable_starttls_auto</tt> - When set to true, detects if STARTTLS is enabled in your SMTP server
266 # and starts to use it.
c927aa0 @dhh Updated documentation
dhh authored Dec 16, 2004
267 #
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored May 16, 2008
268 # * <tt>sendmail_settings</tt> - Allows you to override options for the <tt>:sendmail</tt> delivery method.
269 # * <tt>:location</tt> - The location of the sendmail executable. Defaults to <tt>/usr/sbin/sendmail</tt>.
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
270 # * <tt>:arguments</tt> - The command line arguments. Defaults to <tt>-i -t</tt> with <tt>-f sender@addres</tt>
271 # added automatically before the message is sent.
dc4eec1 @lifo Merge docrails:
lifo authored May 9, 2008
272 #
fbe6c3c @edavis10 Adds a :file delivery_method to save email to a file on disk
edavis10 authored Aug 7, 2009
273 # * <tt>file_settings</tt> - Allows you to override options for the <tt>:file</tt> delivery method.
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
274 # * <tt>:location</tt> - The directory into which emails will be written. Defaults to the application
275 # <tt>tmp/mails</tt>.
fbe6c3c @edavis10 Adds a :file delivery_method to save email to a file on disk
edavis10 authored Aug 8, 2009
276 #
dc4eec1 @lifo Merge docrails:
lifo authored May 9, 2008
277 # * <tt>raise_delivery_errors</tt> - Whether or not errors should be raised if the email fails to be delivered.
c927aa0 @dhh Updated documentation
dhh authored Dec 16, 2004
278 #
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
279 # * <tt>delivery_method</tt> - Defines a delivery method. Possible values are <tt>:smtp</tt> (default),
280 # <tt>:sendmail</tt>, <tt>:test</tt>, and <tt>:file</tt>. Or you may provide a custom delivery method
281 # object eg. MyOwnDeliveryMethodClass.new. See the Mail gem documentation on the interface you need to
282 # implement for a custom delivery agent.
c927aa0 @dhh Updated documentation
dhh authored Dec 16, 2004
283 #
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
284 # * <tt>perform_deliveries</tt> - Determines whether emails are actually sent from Action Mailer when you
285 # call <tt>.deliver</tt> on an mail message or on an Action Mailer method. This is on by default but can
286 # be turned off to aid in functional testing.
c927aa0 @dhh Updated documentation
dhh authored Dec 16, 2004
287 #
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
288 # * <tt>deliveries</tt> - Keeps an array of all the emails sent out through the Action Mailer with
289 # <tt>delivery_method :test</tt>. Most useful for unit and functional testing.
af56c80 @dhh Updated documentation
dhh authored Feb 24, 2005
290 #
452bb1e @jeremy Rename 'defaults' class method to 'default' to reflect that it's a de…
jeremy authored Jan 28, 2010
291 # * <tt>default_charset</tt> - This is now deprecated, use the +default+ method above to
21dcc20 @mikel Fixed up documentation to reflect code change and cleaned up tests of…
mikel authored Jan 27, 2010
292 # set the default +:charset+.
c2e7851 @josevalim Add ActionMailer::Base#enable_starttls_auto option for enabling/disab…
josevalim authored Jan 11, 2009
293 #
452bb1e @jeremy Rename 'defaults' class method to 'default' to reflect that it's a de…
jeremy authored Jan 28, 2010
294 # * <tt>default_content_type</tt> - This is now deprecated, use the +default+ method above
21dcc20 @mikel Fixed up documentation to reflect code change and cleaned up tests of…
mikel authored Jan 26, 2010
295 # to set the default +:content_type+.
c2e7851 @josevalim Add ActionMailer::Base#enable_starttls_auto option for enabling/disab…
josevalim authored Jan 11, 2009
296 #
452bb1e @jeremy Rename 'defaults' class method to 'default' to reflect that it's a de…
jeremy authored Jan 28, 2010
297 # * <tt>default_mime_version</tt> - This is now deprecated, use the +default+ method above
21dcc20 @mikel Fixed up documentation to reflect code change and cleaned up tests of…
mikel authored Jan 26, 2010
298 # to set the default +:mime_version+.
c2e7851 @josevalim Add ActionMailer::Base#enable_starttls_auto option for enabling/disab…
josevalim authored Jan 11, 2009
299 #
452bb1e @jeremy Rename 'defaults' class method to 'default' to reflect that it's a de…
jeremy authored Jan 28, 2010
300 # * <tt>default_implicit_parts_order</tt> - This is now deprecated, use the +default+ method above
21dcc20 @mikel Fixed up documentation to reflect code change and cleaned up tests of…
mikel authored Jan 26, 2010
301 # to set the default +:parts_order+. Parts Order is used when a message is built implicitly
302 # (i.e. multiple parts are assembled from templates which specify the content type in their
303 # filenames) this variable controls how the parts are ordered.
4964d3b @josevalim Make ActionMailer::Base inherit from AbstractController::Base
josevalim authored Dec 22, 2009
304 class Base < AbstractController::Base
dbcf01e @mikel Removing quoting.rb, upgrade to 2.1.3.6, changing all utf-8 reference…
mikel authored Apr 8, 2010
305 include DeliveryMethods
f30d73b Add new class delivery method API.
José Valim and Mikel Lindsaar authored Jan 24, 2010
306 abstract!
307
c03c40b @josevalim Expose a _render_partial hook as thhe _render_template one and make u…
josevalim authored Dec 31, 2009
308 include AbstractController::Logger
83f4d86 @dhh Rename the RenderingController module to just plain Rendering
dhh authored Dec 20, 2009
309 include AbstractController::Rendering
a9751a7 @josevalim Refactor ActionMailer layout and remove legacy one.
josevalim authored Oct 17, 2009
310 include AbstractController::Layouts
684c2dc @josevalim Remove ActionMailer helpers and rely on AbstractController one.
josevalim authored Oct 18, 2009
311 include AbstractController::Helpers
48a3985 @josevalim Also include translation in ActionMailer.
josevalim authored Jan 26, 2010
312 include AbstractController::Translation
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored May 29, 2005
313
ee70d1b @josevalim adv_attr_accessors in ActionMailer are not sent to the views, use the…
josevalim authored Dec 25, 2009
314 helper ActionMailer::MailHelper
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
315
5dead5b Maintain old_api and deprecated_api in different files.
José Valim and Mikel Lindsaar authored Jan 24, 2010
316 include ActionMailer::OldApi
f30d73b Add new class delivery method API.
José Valim and Mikel Lindsaar authored Jan 24, 2010
317 include ActionMailer::DeprecatedApi
cefc136 @mikel Adding options to register observers and interceptors through ActionM…
mikel authored Feb 22, 2010
318
319 delegate :register_observer, :to => Mail
320 delegate :register_interceptor, :to => Mail
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
321
c927aa0 @dhh Updated documentation
dhh authored Dec 16, 2004
322 private_class_method :new #:nodoc:
db045db @dhh Initial
dhh authored Nov 24, 2004
323
e5ab4b0 @jeremy Convert to class_attribute
jeremy authored Jan 31, 2010
324 class_attribute :default_params
9dd65c3 Make defaults accept a hash.
José Valim and Mikel Lindsaar authored Jan 26, 2010
325 self.default_params = {
326 :mime_version => "1.0",
dbcf01e @mikel Removing quoting.rb, upgrade to 2.1.3.6, changing all utf-8 reference…
mikel authored Apr 8, 2010
327 :charset => "UTF-8",
9dd65c3 Make defaults accept a hash.
José Valim and Mikel Lindsaar authored Jan 26, 2010
328 :content_type => "text/plain",
329 :parts_order => [ "text/plain", "text/enriched", "text/html" ]
e5ab4b0 @jeremy Convert to class_attribute
jeremy authored Feb 1, 2010
330 }.freeze
e1c1318 Added delivers_from.
José Valim and Mikel Lindsaar authored Jan 25, 2010
331
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but …
jamis authored Jul 31, 2005
332 class << self
0b05acd @mikel Implementing class level :defaults hash, instead of delivers_from et al
mikel authored Jan 26, 2010
333
bd5ed65 @technoweenie Update ActionMailer so it treats ActionView the same way that ActionC…
technoweenie authored Nov 26, 2007
334 def mailer_name
335 @mailer_name ||= name.underscore
336 end
0750304 @mikel Migrated over to Mail doing delivery.
mikel authored Jan 16, 2010
337 attr_writer :mailer_name
338 alias :controller_path :mailer_name
81c416b @josevalim More refactoring on ActionMailer::Base.
josevalim authored Oct 28, 2009
339
e5ab4b0 @jeremy Convert to class_attribute
jeremy authored Feb 1, 2010
340 def default(value = nil)
341 self.default_params = default_params.merge(value).freeze if value
342 default_params
9dd65c3 Make defaults accept a hash.
José Valim and Mikel Lindsaar authored Jan 26, 2010
343 end
344
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored Oct 16, 2005
345 # Receives a raw email, parses it into an email object, decodes it,
346 # instantiates a new mailer, and passes the email object to the mailer
98dc582 @lifo Merge docrails.
lifo authored May 25, 2008
347 # object's +receive+ method. If you want your mailer to be able to
348 # process incoming messages, you'll need to implement a +receive+
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
349 # method that accepts the raw email string as a parameter:
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored Oct 16, 2005
350 #
351 # class MyMailer < ActionMailer::Base
352 # def receive(mail)
353 # ...
354 # end
355 # end
704daad @josevalim Ensure we just send Ruby Stdlib objects in ActionMailer notifications.
josevalim authored Jan 15, 2010
356 def receive(raw_mail)
731d439 @jaggederest Change event namespace ordering to most-significant first [#4504 stat…
jaggederest authored Apr 27, 2010
357 ActiveSupport::Notifications.instrument("receive.action_mailer") do |payload|
704daad @josevalim Ensure we just send Ruby Stdlib objects in ActionMailer notifications.
josevalim authored Jan 15, 2010
358 mail = Mail.new(raw_mail)
359 set_payload_for_mail(payload, mail)
2a6bc12 @josevalim Add subscriber to ActionMailer.
josevalim authored Jan 13, 2010
360 new.receive(mail)
361 end
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but …
jamis authored Jul 31, 2005
362 end
363
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
364 # Wraps an email delivery inside of Active Support Notifications instrumentation. This
365 # method is actually called by the <tt>Mail::Message</tt> object itself through a call back
366 # when you call <tt>:deliver</tt> on the Mail::Message, calling +deliver_mail+ directly
367 # and passing a Mail::Message will do nothing except tell the logger you sent the email.
e4a989e Added delivery_handler method to mail and implemented in ActionMailer…
José Valim and Mikel Lindsaar authored Jan 25, 2010
368 def deliver_mail(mail) #:nodoc:
731d439 @jaggederest Change event namespace ordering to most-significant first [#4504 stat…
jaggederest authored Apr 28, 2010
369 ActiveSupport::Notifications.instrument("deliver.action_mailer") do |payload|
258ca14 Delegated ActionMailer::Base.deliveries to Mail.deliveries, added cal…
José Valim and Mikel Lindsaar authored Jan 24, 2010
370 self.set_payload_for_mail(payload, mail)
ace7497 Got AM working with Mail yield on delivery_handler and updated tests
José Valim and Mikel Lindsaar authored Jan 25, 2010
371 yield # Let Mail do the delivery actions
258ca14 Delegated ActionMailer::Base.deliveries to Mail.deliveries, added cal…
José Valim and Mikel Lindsaar authored Jan 24, 2010
372 end
373 end
374
99f960a Handle some TODOs and deprecations.
José Valim and Mikel Lindsaar authored Jan 24, 2010
375 def respond_to?(method, *args) #:nodoc:
376 super || action_methods.include?(method.to_s)
377 end
378
379 protected
380
704daad @josevalim Ensure we just send Ruby Stdlib objects in ActionMailer notifications.
josevalim authored Jan 15, 2010
381 def set_payload_for_mail(payload, mail) #:nodoc:
99f960a Handle some TODOs and deprecations.
José Valim and Mikel Lindsaar authored Jan 24, 2010
382 payload[:mailer] = self.name
c905fce @josevalim Add message_id to AM payload and don't send bcc and cc if they were n…
josevalim authored Jan 15, 2010
383 payload[:message_id] = mail.message_id
384 payload[:subject] = mail.subject
385 payload[:to] = mail.to
386 payload[:from] = mail.from
387 payload[:bcc] = mail.bcc if mail.bcc.present?
388 payload[:cc] = mail.cc if mail.cc.present?
389 payload[:date] = mail.date
390 payload[:mail] = mail.encoded
704daad @josevalim Ensure we just send Ruby Stdlib objects in ActionMailer notifications.
josevalim authored Jan 15, 2010
391 end
f30d73b Add new class delivery method API.
José Valim and Mikel Lindsaar authored Jan 24, 2010
392
99f960a Handle some TODOs and deprecations.
José Valim and Mikel Lindsaar authored Jan 24, 2010
393 def method_missing(method, *args) #:nodoc:
f30d73b Add new class delivery method API.
José Valim and Mikel Lindsaar authored Jan 24, 2010
394 if action_methods.include?(method.to_s)
395 new(method, *args).message
396 else
397 super
398 end
399 end
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but …
jamis authored Jul 31, 2005
400 end
401
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
402 attr_internal :message
403
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
404 # Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer
405 # will be initialized according to the named method. If not, the mailer will
406 # remain uninitialized (useful when you only need to invoke the "receive"
407 # method, for instance).
408 def initialize(method_name=nil, *args)
409 super()
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
410 @_message = Mail.new
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
411 process(method_name, *args) if method_name
412 end
413
3fc609e @josevalim Fix ActionMailer test broken in 99d5459
josevalim authored Apr 12, 2010
414 def process(*args) #:nodoc:
415 lookup_context.skip_default_locale!
416 super
417 end
418
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
419 # Allows you to pass random and unusual headers to the new +Mail::Message+ object
420 # which will add them to itself.
421 #
422 # headers['X-Special-Domain-Specific-Header'] = "SecretValue"
423 #
9520166 @mikel Fixed up being able to pass random headers in with headers, or mail. …
mikel authored Jan 26, 2010
424 # You can also pass a hash into headers of header field names and values, which
425 # will then be set on the Mail::Message object:
426 #
05c4ad9 Tidy up tests and docs.
José Valim and Mikel Lindsaar authored Jan 26, 2010
427 # headers 'X-Special-Domain-Specific-Header' => "SecretValue",
428 # 'In-Reply-To' => incoming.message_id
9520166 @mikel Fixed up being able to pass random headers in with headers, or mail. …
mikel authored Jan 26, 2010
429 #
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
430 # The resulting Mail::Message will have the following in it's header:
431 #
432 # X-Special-Domain-Specific-Header: SecretValue
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
433 def headers(args=nil)
434 if args
9520166 @mikel Fixed up being able to pass random headers in with headers, or mail. …
mikel authored Jan 26, 2010
435 @_message.headers(args)
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
436 else
437 @_message
438 end
439 end
c34cfcc @mikel Created mail method for new API
mikel authored Jan 20, 2010
440
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
441 # Allows you to add attachments to an email, like so:
442 #
443 # mail.attachments['filename.jpg'] = File.read('/path/to/filename.jpg')
444 #
445 # If you do this, then Mail will take the file name and work out the mime type
446 # set the Content-Type, Content-Disposition, Content-Transfer-Encoding and
447 # base64 encode the contents of the attachment all for you.
448 #
449 # You can also specify overrides if you want by passing a hash instead of a string:
450 #
451 # mail.attachments['filename.jpg'] = {:mime_type => 'application/x-gzip',
452 # :content => File.read('/path/to/filename.jpg')}
453 #
454 # If you want to use a different encoding than Base64, you can pass an encoding in,
455 # but then it is up to you to pass in the content pre-encoded, and don't expect
456 # Mail to know how to decode this data:
457 #
458 # file_content = SpecialEncode(File.read('/path/to/filename.jpg'))
459 # mail.attachments['filename.jpg'] = {:mime_type => 'application/x-gzip',
460 # :encoding => 'SpecialEncoding',
461 # :content => file_content }
462 #
463 # You can also search for specific attachments:
464 #
465 # # By Filename
466 # mail.attachments['filename.jpg'] #=> Mail::Part object or nil
467 #
468 # # or by index
469 # mail.attachments[0] #=> Mail::Part (first attachment)
470 #
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
471 def attachments
472 @_message.attachments
473 end
dcb9253 Add basic template rendering to new DSL.
José Valim and Mikel Lindsaar authored Jan 22, 2010
474
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
475 # The main method that creates the message and renders the email templates. There are
476 # two ways to call this method, with a block, or without a block.
477 #
6589976 Remove old files, add some information to docs and improve test suite.
José Valim and Mikel Lindsaar authored Jan 26, 2010
478 # Both methods accept a headers hash. This hash allows you to specify the most used headers
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
479 # in an email message, these are:
480 #
481 # * <tt>:subject</tt> - The subject of the message, if this is omitted, ActionMailer will
482 # ask the Rails I18n class for a translated <tt>:subject</tt> in the scope of
483 # <tt>[:actionmailer, mailer_scope, action_name]</tt> or if this is missing, will translate the
484 # humanized version of the <tt>action_name</tt>
485 # * <tt>:to</tt> - Who the message is destined for, can be a string of addresses, or an array
486 # of addresses.
0b05acd @mikel Implementing class level :defaults hash, instead of delivers_from et al
mikel authored Jan 26, 2010
487 # * <tt>:from</tt> - Who the message is from
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
488 # * <tt>:cc</tt> - Who you would like to Carbon-Copy on this email, can be a string of addresses,
489 # or an array of addresses.
490 # * <tt>:bcc</tt> - Who you would like to Blind-Carbon-Copy on this email, can be a string of
491 # addresses, or an array of addresses.
492 # * <tt>:reply_to</tt> - Who to set the Reply-To header of the email to.
493 # * <tt>:date</tt> - The date to say the email was sent on.
494 #
452bb1e @jeremy Rename 'defaults' class method to 'default' to reflect that it's a de…
jeremy authored Jan 28, 2010
495 # You can set default values for any of the above headers (except :date) by using the <tt>default</tt>
0b05acd @mikel Implementing class level :defaults hash, instead of delivers_from et al
mikel authored Jan 26, 2010
496 # class method:
497 #
9dd65c3 Make defaults accept a hash.
José Valim and Mikel Lindsaar authored Jan 26, 2010
498 # class Notifier < ActionMailer::Base
452bb1e @jeremy Rename 'defaults' class method to 'default' to reflect that it's a de…
jeremy authored Jan 28, 2010
499 # self.default :from => 'no-reply@test.lindsaar.net',
500 # :bcc => 'email_logger@test.lindsaar.net',
501 # :reply_to => 'bounces@test.lindsaar.net'
0b05acd @mikel Implementing class level :defaults hash, instead of delivers_from et al
mikel authored Jan 26, 2010
502 # end
503 #
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
504 # If you need other headers not listed above, use the <tt>headers['name'] = value</tt> method.
505 #
6589976 Remove old files, add some information to docs and improve test suite.
José Valim and Mikel Lindsaar authored Jan 26, 2010
506 # When a <tt>:return_path</tt> is specified as header, that value will be used as the 'envelope from'
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
507 # address for the Mail message. Setting this is useful when you want delivery notifications
508 # sent to a different address than the one in <tt>:from</tt>. Mail will actually use the
509 # <tt>:return_path</tt> in preference to the <tt>:sender</tt> in preference to the <tt>:from</tt>
510 # field for the 'envelope from' value.
511 #
512 # If you do not pass a block to the +mail+ method, it will find all templates in the
be35a15 @josevalim Allow to choose the template path and template name used in implicit …
josevalim authored Feb 19, 2010
513 # view paths using by default the mailer name and the method name that it is being
514 # called from, it will then create parts for each of these templates intelligently,
515 # making educated guesses on correct content type and sequence, and return a fully
516 # prepared Mail::Message ready to call <tt>:deliver</tt> on to send.
517 #
518 # For example:
519 #
520 # class Notifier < ActionMailer::Base
521 # default :from => 'no-reply@test.lindsaar.net',
522 #
523 # def welcome
524 # mail(:to => 'mikel@test.lindsaar.net')
525 # end
526 # end
527 #
528 # Will look for all templates at "app/views/notifier" with name "welcome". However, those
529 # can be customized:
530 #
531 # mail(:template_path => 'notifications', :template_name => 'another')
532 #
533 # And now it will look for all templates at "app/views/notifications" with name "another".
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
534 #
535 # If you do pass a block, you can render specific templates of your choice:
536 #
537 # mail(:to => 'mikel@test.lindsaar.net') do |format|
538 # format.text
539 # format.html
540 # end
541 #
542 # You can even render text directly without using a template:
543 #
544 # mail(:to => 'mikel@test.lindsaar.net') do |format|
545 # format.text { render :text => "Hello Mikel!" }
546 # format.html { render :text => "<h1>Hello Mikel!</h1>" }
547 # end
548 #
74a5889 Refactor content type setting, added tests to ensure boundary exists …
José Valim and Mikel Lindsaar authored Jan 26, 2010
549 # Which will render a <tt>multipart/alternative</tt> email with <tt>text/plain</tt> and
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
550 # <tt>text/html</tt> parts.
6589976 Remove old files, add some information to docs and improve test suite.
José Valim and Mikel Lindsaar authored Jan 26, 2010
551 #
552 # The block syntax also allows you to customize the part headers if desired:
553 #
554 # mail(:to => 'mikel@test.lindsaar.net') do |format|
555 # format.text(:content_transfer_encoding => "base64")
556 # format.html
557 # end
558 #
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
559 def mail(headers={}, &block)
560 # Guard flag to prevent both the old and the new API from firing
561 # Should be removed when old API is removed
562 @mail_was_called = true
563 m = @_message
258ca14 Delegated ActionMailer::Base.deliveries to Mail.deliveries, added cal…
José Valim and Mikel Lindsaar authored Jan 24, 2010
564
9dd65c3 Make defaults accept a hash.
José Valim and Mikel Lindsaar authored Jan 26, 2010
565 # At the beginning, do not consider class default for parts order neither content_type
566 content_type = headers[:content_type]
567 parts_order = headers[:parts_order]
1cd5592 First work on implicit multipart.
José Valim and Mikel Lindsaar authored Jan 22, 2010
568
08b07b6 @mikel Adding ability to pass proc's to the ActionMailer class default method
mikel authored May 2, 2010
569 # Call all the procs (if any)
570 default_values = self.class.default.merge(self.class.default) do |k,v|
ceaa100 @mikel Adding ability for the procs to be called within the instance, allows…
mikel authored May 2, 2010
571 v.respond_to?(:call) ? v.bind(self).call : v
08b07b6 @mikel Adding ability to pass proc's to the ActionMailer class default method
mikel authored May 2, 2010
572 end
573
b5f9a9f @josevalim Move set_fields! to the old API module.
josevalim authored Apr 12, 2010
574 # Handle defaults
08b07b6 @mikel Adding ability to pass proc's to the ActionMailer class default method
mikel authored May 2, 2010
575 headers = headers.reverse_merge(default_values)
9dd65c3 Make defaults accept a hash.
José Valim and Mikel Lindsaar authored Jan 26, 2010
576 headers[:subject] ||= default_i18n_subject
b5f9a9f @josevalim Move set_fields! to the old API module.
josevalim authored Apr 12, 2010
577
578 # Apply charset at the beginning so all fields are properly quoted
579 m.charset = charset = headers[:charset]
580
581 # Set configure delivery behavior
582 wrap_delivery_behavior!(headers.delete(:delivery_method))
583
584 # Assign all headers except parts_order, content_type and body
b4fd5e6 @josevalim template_name and template_path should not be added to mail headers.
josevalim authored Apr 13, 2010
585 assignable = headers.except(:parts_order, :content_type, :body, :template_name, :template_path)
b5f9a9f @josevalim Move set_fields! to the old API module.
josevalim authored Apr 12, 2010
586 assignable.each { |k, v| m[k] = v }
951397b Get implicit multipart and attachments working together.
José Valim and Mikel Lindsaar authored Jan 22, 2010
587
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
588 # Render the templates and blocks
39a1b06 Deprecate old defaults API.
José Valim and Mikel Lindsaar authored Jan 26, 2010
589 responses, explicit_order = collect_responses_and_parts_order(headers, &block)
b5f9a9f @josevalim Move set_fields! to the old API module.
josevalim authored Apr 12, 2010
590 create_parts_from_responses(m, responses)
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
591
b5f9a9f @josevalim Move set_fields! to the old API module.
josevalim authored Apr 12, 2010
592 # Setup content type, reapply charset and handle parts order
9dd65c3 Make defaults accept a hash.
José Valim and Mikel Lindsaar authored Jan 26, 2010
593 m.content_type = set_content_type(m, content_type, headers[:content_type])
951397b Get implicit multipart and attachments working together.
José Valim and Mikel Lindsaar authored Jan 22, 2010
594 m.charset = charset
595
e7e4ed4 Set sort order for explicit parts from the collector's template sequence
José Valim and Mikel Lindsaar authored Jan 24, 2010
596 if m.multipart?
9dd65c3 Make defaults accept a hash.
José Valim and Mikel Lindsaar authored Jan 26, 2010
597 parts_order ||= explicit_order || headers[:parts_order]
598 m.body.set_sort_order(parts_order)
951397b Get implicit multipart and attachments working together.
José Valim and Mikel Lindsaar authored Jan 22, 2010
599 m.body.sort_parts!
600 end
bb9d71f Move class methods to deprecated stuff.
José Valim and Mikel Lindsaar authored Jan 22, 2010
601
c34cfcc @mikel Created mail method for new API
mikel authored Jan 20, 2010
602 m
603 end
604
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
605 protected
606
9dd65c3 Make defaults accept a hash.
José Valim and Mikel Lindsaar authored Jan 26, 2010
607 def set_content_type(m, user_content_type, class_default)
74a5889 Refactor content type setting, added tests to ensure boundary exists …
José Valim and Mikel Lindsaar authored Jan 26, 2010
608 params = m.content_type_parameters || {}
609 case
610 when user_content_type.present?
611 user_content_type
612 when m.has_attachments?
613 ["multipart", "mixed", params]
614 when m.multipart?
615 ["multipart", "alternative", params]
616 else
b6b3db6 @mikel Fixed bug on HTML only emails getting set to text/plain
mikel authored Jan 28, 2010
617 m.content_type || class_default
74a5889 Refactor content type setting, added tests to ensure boundary exists …
José Valim and Mikel Lindsaar authored Jan 26, 2010
618 end
619 end
620
9dd65c3 Make defaults accept a hash.
José Valim and Mikel Lindsaar authored Jan 26, 2010
621 def default_i18n_subject #:nodoc:
5c3ef8c Refactor subject with i18n.
José Valim and Mikel Lindsaar authored Jan 23, 2010
622 mailer_scope = self.class.mailer_name.gsub('/', '.')
9dd65c3 Make defaults accept a hash.
José Valim and Mikel Lindsaar authored Jan 26, 2010
623 I18n.t(:subject, :scope => [:actionmailer, mailer_scope, action_name], :default => action_name.humanize)
5c3ef8c Refactor subject with i18n.
José Valim and Mikel Lindsaar authored Jan 23, 2010
624 end
625
39a1b06 Deprecate old defaults API.
José Valim and Mikel Lindsaar authored Jan 26, 2010
626 def collect_responses_and_parts_order(headers) #:nodoc:
627 responses, parts_order = [], nil
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
628
629 if block_given?
a09e992 @josevalim Ensure details are frozen after @details_keys lookup. The implementat…
josevalim authored Mar 27, 2010
630 collector = ActionMailer::Collector.new(lookup_context) { render(action_name) }
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
631 yield(collector)
39a1b06 Deprecate old defaults API.
José Valim and Mikel Lindsaar authored Jan 26, 2010
632 parts_order = collector.responses.map { |r| r[:content_type] }
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
633 responses = collector.responses
634 elsif headers[:body]
635 responses << {
be35a15 @josevalim Allow to choose the template path and template name used in implicit …
josevalim authored Feb 19, 2010
636 :body => headers.delete(:body),
452bb1e @jeremy Rename 'defaults' class method to 'default' to reflect that it's a de…
jeremy authored Jan 28, 2010
637 :content_type => self.class.default[:content_type] || "text/plain"
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
638 }
639 else
be35a15 @josevalim Allow to choose the template path and template name used in implicit …
josevalim authored Feb 19, 2010
640 templates_path = headers.delete(:template_path) || self.class.mailer_name
641 templates_name = headers.delete(:template_name) || action_name
642
643 each_template(templates_path, templates_name) do |template|
f28d856 @josevalim Improve performance of the rendering stack by freezing formats as a s…
josevalim authored Mar 19, 2010
644 self.formats = template.formats
645
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
646 responses << {
2a12686 @josevalim Allow anything that responds to render to be given as :template and u…
josevalim authored Mar 12, 2010
647 :body => render(:template => template),
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
648 :content_type => template.mime_type.to_s
649 }
650 end
651 end
652
39a1b06 Deprecate old defaults API.
José Valim and Mikel Lindsaar authored Jan 26, 2010
653 [responses, parts_order]
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
654 end
655
be35a15 @josevalim Allow to choose the template path and template name used in implicit …
josevalim authored Feb 19, 2010
656 def each_template(paths, name, &block) #:nodoc:
41af6d9 @jeremy Use Array.wrap not Array()
jeremy authored Mar 18, 2010
657 Array.wrap(paths).each do |path|
36eb1a6 @josevalim Bring AM up to date with new rendering stack.
josevalim authored Mar 8, 2010
658 templates = lookup_context.find_all(name, path)
00d6271 @josevalim Clean up the API required from ActionView::Template.
josevalim authored Mar 9, 2010
659 templates = templates.uniq_by { |t| t.formats }
0ece244 Ensure implicit multipart templates with locale works as expected.
José Valim and Mikel Lindsaar authored Jan 24, 2010
660
36eb1a6 @josevalim Bring AM up to date with new rendering stack.
josevalim authored Mar 8, 2010
661 unless templates.empty?
662 templates.each(&block)
663 return
99f960a Handle some TODOs and deprecations.
José Valim and Mikel Lindsaar authored Jan 24, 2010
664 end
665 end
666 end
667
b5f9a9f @josevalim Move set_fields! to the old API module.
josevalim authored Apr 12, 2010
668 def create_parts_from_responses(m, responses) #:nodoc:
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
669 if responses.size == 1 && !m.has_attachments?
9dd65c3 Make defaults accept a hash.
José Valim and Mikel Lindsaar authored Jan 26, 2010
670 responses[0].each { |k,v| m[k] = v }
74a5889 Refactor content type setting, added tests to ensure boundary exists …
José Valim and Mikel Lindsaar authored Jan 26, 2010
671 elsif responses.size > 1 && m.has_attachments?
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
672 container = Mail::Part.new
74a5889 Refactor content type setting, added tests to ensure boundary exists …
José Valim and Mikel Lindsaar authored Jan 26, 2010
673 container.content_type = "multipart/alternative"
b5f9a9f @josevalim Move set_fields! to the old API module.
josevalim authored Apr 12, 2010
674 responses.each { |r| insert_part(container, r, m.charset) }
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
675 m.add_part(container)
676 else
b5f9a9f @josevalim Move set_fields! to the old API module.
josevalim authored Apr 12, 2010
677 responses.each { |r| insert_part(m, r, m.charset) }
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
678 end
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored May 29, 2005
679 end
680
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
681 def insert_part(container, response, charset) #:nodoc:
682 response[:charset] ||= charset
683 part = Mail::Part.new(response)
684 container.add_part(part)
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored May 29, 2005
685 end
3fad0cd @dhh Added support for charsets for both subject and body. The default cha…
dhh authored Feb 19, 2005
686
ef5dada @nex3 Only run load hooks once a file has been fully loaded.
nex3 authored Apr 27, 2010
687 ActiveSupport.run_load_hooks(:action_mailer, self)
db045db @dhh Initial
dhh authored Nov 24, 2004
688 end
689 end
Something went wrong with that request. Please try again.