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