Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 649 lines (567 sloc) 26.462 kb
a9751a7 @josevalim Refactor ActionMailer layout and remove legacy one.
josevalim authored
1 require 'active_support/core_ext/class'
616ebb8 @josevalim Remove unused code paths and require mail only when it's needed.
josevalim authored
2 require 'mail'
a288082 @mikel Adding :transfer_encoding -> :content_transfer_encoding as part of Tm…
mikel authored
3 require 'action_mailer/tmail_compat'
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 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
12 # $ script/generate mailer Notifier
13 #
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
14 # The generated model inherits from ActionMailer::Base. Emails are defined by creating methods within the model which are then
15 # used to set variables to be used in the mail template, to change options on the mail, or
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
16 # to add attachments.
17 #
18 # Examples:
19 #
20 # class Notifier < ActionMailer::Base
21 # def signup_notification(recipient)
22 # recipients recipient.email_address_with_name
c3f53f4 @lifo Merge docrails
lifo authored
23 # bcc ["bcc@example.com", "Order Watcher <watcher@example.com>"]
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
24 # from "system@example.com"
25 # subject "New account information"
a037458 @josevalim Bring body(Hash) behavior back.
josevalim authored
26 # body :account => recipient
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
27 # end
28 # end
29 #
30 # Mailer methods have the following configuration methods available.
31 #
32 # * <tt>recipients</tt> - Takes one or more email addresses. These addresses are where your email will be delivered to. Sets the <tt>To:</tt> header.
33 # * <tt>subject</tt> - The subject of your email. Sets the <tt>Subject:</tt> header.
34 # * <tt>from</tt> - Who the email you are sending is from. Sets the <tt>From:</tt> header.
35 # * <tt>cc</tt> - Takes one or more email addresses. These addresses will receive a carbon copy of your email. Sets the <tt>Cc:</tt> header.
cf6299d Add ActionMailer#reply_to. [#245 state:resolved]
Adam authored
36 # * <tt>bcc</tt> - Takes one or more email addresses. These addresses will receive a blind carbon copy of your email. Sets the <tt>Bcc:</tt> header.
37 # * <tt>reply_to</tt> - Takes one or more email addresses. These addresses will be listed as the default recipients when replying to your email. Sets the <tt>Reply-To:</tt> header.
dba196c @lifo Merge docrails
lifo authored
38 # * <tt>sent_on</tt> - The date on which the message was sent. If not set, the header will be set by the delivery agent.
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
39 # * <tt>content_type</tt> - Specify the content type of the message. Defaults to <tt>text/plain</tt>.
40 # * <tt>headers</tt> - Specify additional headers to be set for the message, e.g. <tt>headers 'X-Mail-Count' => 107370</tt>.
41 #
5c0d38f @dhh Fixed that a return-path header would be ignored (closes #7572) [joost]
dhh authored
42 # When a <tt>headers 'return-path'</tt> is specified, that value will be used as the 'envelope from'
43 # address. Setting this is useful when you want delivery notifications sent to a different address than
44 # the one in <tt>from</tt>.
45 #
20bd4bd @dhh Updated docs and otherwise
dhh authored
46 #
47 # = Mailer views
48 #
98dc582 @lifo Merge docrails.
lifo authored
49 # Like Action Controller, each mailer class has a corresponding view directory
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
50 # in which each method of the class looks for a template with its name.
21187c0 @dhh Apply the rest of Chads patch
dhh authored
51 # To define a template to be used with a mailing, create an <tt>.erb</tt> file with the same name as the method
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
52 # in your mailer model. For example, in the mailer defined above, the template at
21187c0 @dhh Apply the rest of Chads patch
dhh authored
53 # <tt>app/views/notifier/signup_notification.erb</tt> would be used to generate the email.
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
54 #
55 # Variables defined in the model are accessible as instance variables in the view.
56 #
57 # Emails by default are sent in plain text, so a sample view for our model example might look like this:
58 #
59 # Hi <%= @account.name %>,
60 # Thanks for joining our service! Please check back often.
61 #
20bd4bd @dhh Updated docs and otherwise
dhh authored
62 # You can even use Action Pack helpers in these views. For example:
63 #
64 # You got a new note!
ee70d1b @josevalim adv_attr_accessors in ActionMailer are not sent to the views, use the…
josevalim authored
65 # <%= truncate(@note.body, 25) %>
66 #
67 # If you need to access the subject, from or the recipients in the view, you can do that through mailer object:
68 #
69 # You got a new note from <%= mailer.from %>!
70 # <%= truncate(@note.body, 25) %>
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
71 #
20bd4bd @dhh Updated docs and otherwise
dhh authored
72 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
73 # = Generating URLs
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
74 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
75 # URLs can be generated in mailer views using <tt>url_for</tt> or named routes.
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
76 # Unlike controllers from Action Pack, the mailer instance doesn't have any context about the incoming request,
77 # so you'll need to provide all of the details needed to generate a URL.
20bd4bd @dhh Updated docs and otherwise
dhh authored
78 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
79 # 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
80 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
81 # <%= url_for(:host => "example.com", :controller => "welcome", :action => "greeting") %>
20bd4bd @dhh Updated docs and otherwise
dhh authored
82 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
83 # 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
84 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
85 # <%= users_url(:host => "example.com") %>
86 #
87 # You will want to avoid using the <tt>name_of_route_path</tt> form of named routes because it doesn't make sense to
88 # generate relative URLs in email messages.
89 #
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
90 # It is also possible to set a default host that will be used in all mailers by setting the <tt>:host</tt> option in
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
91 # the <tt>ActionMailer::Base.default_url_options</tt> hash as follows:
92 #
93 # ActionMailer::Base.default_url_options[:host] = "example.com"
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
94 #
dc4eec1 @lifo Merge docrails:
lifo authored
95 # 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
96 #
97 # config.action_mailer.default_url_options = { :host => "example.com" }
20bd4bd @dhh Updated docs and otherwise
dhh authored
98 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
99 # If you do decide to set a default <tt>:host</tt> for your mailers you will want to use the
100 # <tt>:only_path => false</tt> option when using <tt>url_for</tt>. This will ensure that absolute URLs are generated because
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
101 # the <tt>url_for</tt> view helper will, by default, generate relative URLs when a <tt>:host</tt> option isn't
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
102 # explicitly provided.
20bd4bd @dhh Updated docs and otherwise
dhh authored
103 #
104 # = Sending mail
105 #
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
106 # 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
107 # for delivery later:
108 #
109 # Notifier.deliver_signup_notification(david) # sends the email
110 # mail = Notifier.create_signup_notification(david) # => a tmail object
111 # Notifier.deliver(mail)
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
112 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
113 # You never instantiate your mailer class. Rather, your delivery instance
114 # methods are automatically wrapped in class methods that start with the word
115 # <tt>deliver_</tt> followed by the name of the mailer method that you would
116 # like to deliver. The <tt>signup_notification</tt> method defined above is
117 # delivered by invoking <tt>Notifier.deliver_signup_notification</tt>.
118 #
20bd4bd @dhh Updated docs and otherwise
dhh authored
119 #
120 # = HTML email
121 #
21187c0 @dhh Apply the rest of Chads patch
dhh authored
122 # To send mail as HTML, make sure your view (the <tt>.erb</tt> file) generates HTML and
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
123 # set the content type to html.
124 #
125 # class MyMailer < ActionMailer::Base
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
126 # def signup_notification(recipient)
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored
127 # recipients recipient.email_address_with_name
128 # subject "New account information"
129 # from "system@example.com"
130 # body :account => recipient
131 # content_type "text/html"
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
132 # end
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
133 # end
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
134 #
20bd4bd @dhh Updated docs and otherwise
dhh authored
135 #
136 # = Multipart email
137 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
138 # You can explicitly specify multipart messages:
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
139 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
140 # class ApplicationMailer < ActionMailer::Base
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
141 # def signup_notification(recipient)
142 # recipients recipient.email_address_with_name
143 # subject "New account information"
144 # from "system@example.com"
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored
145 # content_type "multipart/alternative"
f00cbf7 @josevalim Bring render_message back for 2.3 compatibility.
josevalim authored
146 # body :account => recipient
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
147 #
148 # part :content_type => "text/html",
f00cbf7 @josevalim Bring render_message back for 2.3 compatibility.
josevalim authored
149 # :data => render_message("signup-as-html")
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
150 #
151 # part "text/plain" do |p|
f00cbf7 @josevalim Bring render_message back for 2.3 compatibility.
josevalim authored
152 # p.body = render_message("signup-as-plain")
a288082 @mikel Adding :transfer_encoding -> :content_transfer_encoding as part of Tm…
mikel authored
153 # p.content_transfer_encoding = "base64"
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
154 # end
155 # end
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
156 # end
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
157 #
98dc582 @lifo Merge docrails.
lifo authored
158 # Multipart messages can also be used implicitly because Action Mailer will automatically
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
159 # detect and use multipart templates, where each template is named after the name of the action, followed
160 # 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
161 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
162 # For example, if the following templates existed:
21187c0 @dhh Apply the rest of Chads patch
dhh authored
163 # * signup_notification.text.plain.erb
164 # * signup_notification.text.html.erb
165 # * signup_notification.text.xml.builder
166 # * signup_notification.text.x-yaml.erb
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
167 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
168 # Each would be rendered and added as a separate part to the message,
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored
169 # with the corresponding content type. The content type for the entire
170 # message is automatically set to <tt>multipart/alternative</tt>, which indicates
171 # that the email contains multiple different representations of the same email
172 # body. The same body hash is passed to each template.
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
173 #
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored
174 # Implicit template rendering is not performed if any attachments or parts have been added to the email.
175 # This means that you'll have to manually add each part to the email and set the content type of the email
176 # to <tt>multipart/alternative</tt>.
20bd4bd @dhh Updated docs and otherwise
dhh authored
177 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
178 # = Attachments
20bd4bd @dhh Updated docs and otherwise
dhh authored
179 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
180 # Attachments can be added by using the +attachment+ method.
181 #
182 # Example:
183 #
184 # class ApplicationMailer < ActionMailer::Base
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
185 # # attachments
186 # def signup_notification(recipient)
187 # recipients recipient.email_address_with_name
188 # subject "New account information"
189 # from "system@example.com"
190 #
191 # attachment :content_type => "image/jpeg",
192 # :body => File.read("an-image.jpg")
193 #
194 # attachment "application/pdf" do |a|
195 # a.body = generate_your_pdf_here()
196 # end
db045db @dhh Initial
dhh authored
197 # end
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
198 # end
c927aa0 @dhh Updated documentation
dhh authored
199 #
20bd4bd @dhh Updated docs and otherwise
dhh authored
200 #
c927aa0 @dhh Updated documentation
dhh authored
201 # = Configuration options
202 #
203 # These options are specified on the class level, like <tt>ActionMailer::Base.template_root = "/my/templates"</tt>
204 #
64092de @fxn Improve documentation coverage and markup
fxn authored
205 # * <tt>template_root</tt> - Determines the base from which template references will be made.
c927aa0 @dhh Updated documentation
dhh authored
206 #
207 # * <tt>logger</tt> - the logger is used for generating information on the mailing run if available.
208 # Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers.
209 #
64092de @fxn Improve documentation coverage and markup
fxn authored
210 # * <tt>smtp_settings</tt> - Allows detailed configuration for <tt>:smtp</tt> delivery method:
dc4eec1 @lifo Merge docrails:
lifo authored
211 # * <tt>:address</tt> - Allows you to use a remote mail server. Just change it from its default "localhost" setting.
212 # * <tt>:port</tt> - On the off chance that your mail server doesn't run on port 25, you can change it.
213 # * <tt>:domain</tt> - If you need to specify a HELO domain, you can do it here.
214 # * <tt>:user_name</tt> - If your mail server requires authentication, set the username in this setting.
215 # * <tt>:password</tt> - If your mail server requires authentication, set the password in this setting.
b2504f8 @josh Tidy up ActionMailer rendering logic to take advantage of view path c…
josh authored
216 # * <tt>:authentication</tt> - If your mail server requires authentication, you need to specify the authentication type here.
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored
217 # This is a symbol and one of <tt>:plain</tt>, <tt>:login</tt>, <tt>:cram_md5</tt>.
c2e7851 @josevalim Add ActionMailer::Base#enable_starttls_auto option for enabling/disab…
josevalim authored
218 # * <tt>:enable_starttls_auto</tt> - When set to true, detects if STARTTLS is enabled in your SMTP server and starts to use it.
219 # It works only on Ruby >= 1.8.7 and Ruby >= 1.9. Default is true.
c927aa0 @dhh Updated documentation
dhh authored
220 #
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored
221 # * <tt>sendmail_settings</tt> - Allows you to override options for the <tt>:sendmail</tt> delivery method.
222 # * <tt>:location</tt> - The location of the sendmail executable. Defaults to <tt>/usr/sbin/sendmail</tt>.
223 # * <tt>:arguments</tt> - The command line arguments. Defaults to <tt>-i -t</tt>.
dc4eec1 @lifo Merge docrails:
lifo authored
224 #
fbe6c3c @edavis10 Adds a :file delivery_method to save email to a file on disk
edavis10 authored
225 # * <tt>file_settings</tt> - Allows you to override options for the <tt>:file</tt> delivery method.
226 # * <tt>:location</tt> - The directory into which emails will be written. Defaults to the application <tt>tmp/mails</tt>.
227 #
dc4eec1 @lifo Merge docrails:
lifo authored
228 # * <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
229 #
fbe6c3c @edavis10 Adds a :file delivery_method to save email to a file on disk
edavis10 authored
230 # * <tt>delivery_method</tt> - Defines a delivery method. Possible values are <tt>:smtp</tt> (default), <tt>:sendmail</tt>, <tt>:test</tt>,
f4f7677 @matthewrudy abstract all of the ActionMailer delivery methods into their own clas…
matthewrudy authored
231 # and <tt>:file</tt>. Or you may provide a custom delivery method object eg. MyOwnDeliveryMethodClass.new
c927aa0 @dhh Updated documentation
dhh authored
232 #
dc4eec1 @lifo Merge docrails:
lifo authored
233 # * <tt>perform_deliveries</tt> - Determines whether <tt>deliver_*</tt> methods are actually carried out. By default they are,
c927aa0 @dhh Updated documentation
dhh authored
234 # but this can be turned off to help functional testing.
235 #
64092de @fxn Improve documentation coverage and markup
fxn authored
236 # * <tt>deliveries</tt> - Keeps an array of all the emails sent out through the Action Mailer with <tt>delivery_method :test</tt>. Most useful
c927aa0 @dhh Updated documentation
dhh authored
237 # for unit and functional testing.
af56c80 @dhh Updated documentation
dhh authored
238 #
b2504f8 @josh Tidy up ActionMailer rendering logic to take advantage of view path c…
josh authored
239 # * <tt>default_charset</tt> - The default charset used for the body and to encode the subject. Defaults to UTF-8. You can also
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored
240 # pick a different charset from inside a method with +charset+.
c2e7851 @josevalim Add ActionMailer::Base#enable_starttls_auto option for enabling/disab…
josevalim authored
241 #
475bd74 @dhh Fix docs (closes #2598)
dhh authored
242 # * <tt>default_content_type</tt> - The default content type used for the main part of the message. Defaults to "text/plain". You
b2504f8 @josh Tidy up ActionMailer rendering logic to take advantage of view path c…
josh authored
243 # can also pick a different content type from inside a method with +content_type+.
c2e7851 @josevalim Add ActionMailer::Base#enable_starttls_auto option for enabling/disab…
josevalim authored
244 #
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored
245 # * <tt>default_mime_version</tt> - The default mime version used for the message. Defaults to <tt>1.0</tt>. You
246 # can also pick a different value from inside a method with +mime_version+.
c2e7851 @josevalim Add ActionMailer::Base#enable_starttls_auto option for enabling/disab…
josevalim authored
247 #
475bd74 @dhh Fix docs (closes #2598)
dhh authored
248 # * <tt>default_implicit_parts_order</tt> - When a message is built implicitly (i.e. multiple parts are assembled from templates
5c98152 @jamis Better multipart support with implicit multipart/alternative and sort…
jamis authored
249 # which specify the content type in their filenames) this variable controls how the parts are ordered. Defaults to
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored
250 # <tt>["text/html", "text/enriched", "text/plain"]</tt>. Items that appear first in the array have higher priority in the mail client
5c98152 @jamis Better multipart support with implicit multipart/alternative and sort…
jamis authored
251 # and appear last in the mime encoded message. You can also pick a different order from inside a method with
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored
252 # +implicit_parts_order+.
4964d3b @josevalim Make ActionMailer::Base inherit from AbstractController::Base
josevalim authored
253 class Base < AbstractController::Base
47e5caa @josevalim Merge Mail with latest Rails and move mail gem to Gemfile.
josevalim authored
254 include Quoting
ee70d1b @josevalim adv_attr_accessors in ActionMailer are not sent to the views, use the…
josevalim authored
255 extend AdvAttrAccessor
a9751a7 @josevalim Refactor ActionMailer layout and remove legacy one.
josevalim authored
256
c03c40b @josevalim Expose a _render_partial hook as thhe _render_template one and make u…
josevalim authored
257 include AbstractController::Logger
83f4d86 @dhh Rename the RenderingController module to just plain Rendering
dhh authored
258 include AbstractController::Rendering
976c264 @josevalim Extracted localized_cache.rb from ActionController, added it to Abstr…
josevalim authored
259 include AbstractController::LocalizedCache
a9751a7 @josevalim Refactor ActionMailer layout and remove legacy one.
josevalim authored
260 include AbstractController::Layouts
684c2dc @josevalim Remove ActionMailer helpers and rely on AbstractController one.
josevalim authored
261 include AbstractController::Helpers
f564f94 @josevalim Remove duplicated url_for code and move methods shared between Action…
josevalim authored
262 include AbstractController::UrlFor
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
418c3f8 @josevalim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
265 include ActionMailer::DeprecatedBody
266
e10f51b @josevalim Refactor delivery methods.
josevalim authored
267 include ActionMailer::DeliveryMethods
268
c927aa0 @dhh Updated documentation
dhh authored
269 private_class_method :new #:nodoc:
db045db @dhh Initial
dhh authored
270
271 @@raise_delivery_errors = true
272 cattr_accessor :raise_delivery_errors
273
274 @@perform_deliveries = true
275 cattr_accessor :perform_deliveries
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
276
db045db @dhh Initial
dhh authored
277 @@deliveries = []
278 cattr_accessor :deliveries
279
3fad0cd @dhh Added support for charsets for both subject and body. The default cha…
dhh authored
280 @@default_charset = "utf-8"
281 cattr_accessor :default_charset
282
100fd72 @jamis Added a "content_type" accessor to allow messages to explicitly speci…
jamis authored
283 @@default_content_type = "text/plain"
284 cattr_accessor :default_content_type
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
285
45b5555 @jamis Make mime version default to 1.0. closes #2323
jamis authored
286 @@default_mime_version = "1.0"
dca4d4e @jamis Multipart messages specify a MIME-Version header automatically #2003 …
jamis authored
287 cattr_accessor :default_mime_version
100fd72 @jamis Added a "content_type" accessor to allow messages to explicitly speci…
jamis authored
288
c039bcd @mikel Moved sort_parts into Mail, updated mail requirement to 1.4.2
mikel authored
289 # This specifies the order that the parts of a multipart email will be. Usually you put
290 # text/plain at the top so someone without a MIME capable email reader can read the plain
291 # text of your email first.
292 #
293 # Any content type that is not listed here will be inserted in the order you add them to
294 # the email after the content types you list here.
295 @@default_implicit_parts_order = [ "text/plain", "text/enriched", "text/html" ]
5c98152 @jamis Better multipart support with implicit multipart/alternative and sort…
jamis authored
296 cattr_accessor :default_implicit_parts_order
297
ee70d1b @josevalim adv_attr_accessors in ActionMailer are not sent to the views, use the…
josevalim authored
298 @@protected_instance_variables = %w(@parts @mail)
81c416b @josevalim More refactoring on ActionMailer::Base.
josevalim authored
299 cattr_reader :protected_instance_variables
28bf2fa @josh Protect body ivar from being clobbered by the mailer template assigns
josh authored
300
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
301 # Specify the BCC addresses for the message
302 adv_attr_accessor :bcc
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
303
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
304 # Specify the CC addresses for the message.
305 adv_attr_accessor :cc
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
306
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
307 # Specify the charset to use for the message. This defaults to the
308 # +default_charset+ specified for ActionMailer::Base.
309 adv_attr_accessor :charset
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
310
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
311 # Specify the content type for the message. This defaults to <tt>text/plain</tt>
312 # in most cases, but can be automatically set in some situations.
313 adv_attr_accessor :content_type
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
314
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
315 # Specify the from address for the message.
316 adv_attr_accessor :from
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
317
cf6299d Add ActionMailer#reply_to. [#245 state:resolved]
Adam authored
318 # Specify the address (if different than the "from" address) to direct
319 # replies to this message.
320 adv_attr_accessor :reply_to
321
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
322 # Specify additional headers to be added to the message.
323 adv_attr_accessor :headers
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
324
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
325 # Specify the order in which parts should be sorted, based on content-type.
326 # This defaults to the value for the +default_implicit_parts_order+.
327 adv_attr_accessor :implicit_parts_order
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
328
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
329 # Defaults to "1.0", but may be explicitly given if needed.
330 adv_attr_accessor :mime_version
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
331
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
332 # The recipient addresses for the message, either as a string (for a single
333 # address) or an array (for multiple addresses).
334 adv_attr_accessor :recipients
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
335
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
336 # The date on which the message was sent. If not set (the default), the
337 # header will be set by the delivery agent.
338 adv_attr_accessor :sent_on
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
339
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
340 # Specify the subject of the message.
341 adv_attr_accessor :subject
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
342
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
343 # Specify the template name to use for current message. This is the "base"
344 # template name, without the extension or directory, and may be used to
345 # have multiple mailer methods share the same template.
346 adv_attr_accessor :template
165097e @dhh Added access to custom headers, like cc, bcc, and reply-to #268 [Andr…
dhh authored
347
bd5ed65 @technoweenie Update ActionMailer so it treats ActionView the same way that ActionC…
technoweenie authored
348 # Override the mailer name, which defaults to an inflected version of the
349 # mailer's class name. If you want to use a template in a non-standard
350 # location, you can use this to specify that location.
4964d3b @josevalim Make ActionMailer::Base inherit from AbstractController::Base
josevalim authored
351 adv_attr_accessor :mailer_name
418c3f8 @josevalim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
352
4964d3b @josevalim Make ActionMailer::Base inherit from AbstractController::Base
josevalim authored
353 # Expose the internal mail
354 attr_reader :mail
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
355
418c3f8 @josevalim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
356 # Alias controller_path to mailer_name so render :partial in views work.
357 alias :controller_path :mailer_name
43d5504 @josevalim Move all render and layout pieces required in ActionMailer from Actio…
josevalim authored
358
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but …
jamis authored
359 class << self
81c416b @josevalim More refactoring on ActionMailer::Base.
josevalim authored
360
bd5ed65 @technoweenie Update ActionMailer so it treats ActionView the same way that ActionC…
technoweenie authored
361 def mailer_name
362 @mailer_name ||= name.underscore
363 end
0750304 @mikel Migrated over to Mail doing delivery.
mikel authored
364 attr_writer :mailer_name
365
366 alias :controller_path :mailer_name
81c416b @josevalim More refactoring on ActionMailer::Base.
josevalim authored
367
3cf773b @floehopper ActionMailer should respond_to? to methods handled by method_missing …
floehopper authored
368 def respond_to?(method_symbol, include_private = false) #:nodoc:
e10f51b @josevalim Refactor delivery methods.
josevalim authored
369 matches_dynamic_method?(method_symbol) || super
3cf773b @floehopper ActionMailer should respond_to? to methods handled by method_missing …
floehopper authored
370 end
371
372 def method_missing(method_symbol, *parameters) #:nodoc:
a62e9e9 @mocoso Fix for ActionMailer::Base.method_missing so that it raises NoMethodE…
mocoso authored
373 if match = matches_dynamic_method?(method_symbol)
374 case match[1]
375 when 'create' then new(match[2], *parameters).mail
376 when 'deliver' then new(match[2], *parameters).deliver!
377 when 'new' then nil
c65075f @mocoso Fixed method_missing for ActionMailer so it no longer matches methods…
mocoso authored
378 else super
a62e9e9 @mocoso Fix for ActionMailer::Base.method_missing so that it raises NoMethodE…
mocoso authored
379 end
380 else
381 super
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but …
jamis authored
382 end
383 end
384
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
385 # Receives a raw email, parses it into an email object, decodes it,
386 # instantiates a new mailer, and passes the email object to the mailer
98dc582 @lifo Merge docrails.
lifo authored
387 # object's +receive+ method. If you want your mailer to be able to
388 # process incoming messages, you'll need to implement a +receive+
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
389 # method that accepts the email object as a parameter:
390 #
391 # class MyMailer < ActionMailer::Base
392 # def receive(mail)
393 # ...
394 # end
395 # end
704daad @josevalim Ensure we just send Ruby Stdlib objects in ActionMailer notifications.
josevalim authored
396 def receive(raw_mail)
397 ActiveSupport::Notifications.instrument("action_mailer.receive") do |payload|
398 mail = Mail.new(raw_mail)
399 set_payload_for_mail(payload, mail)
2a6bc12 @josevalim Add subscriber to ActionMailer.
josevalim authored
400 new.receive(mail)
401 end
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but …
jamis authored
402 end
403
404 # Deliver the given mail object directly. This can be used to deliver
405 # a preconstructed mail object, like:
406 #
407 # email = MyMailer.create_some_mail(parameters)
408 # email.set_some_obscure_header "frobnicate"
409 # MyMailer.deliver(email)
410 def deliver(mail)
0750304 @mikel Migrated over to Mail doing delivery.
mikel authored
411 raise "no mail object available for delivery!" unless mail
412
413 begin
e10f51b @josevalim Refactor delivery methods.
josevalim authored
414 ActiveSupport::Notifications.instrument("action_mailer.deliver", :mailer => self.name) do |payload|
0750304 @mikel Migrated over to Mail doing delivery.
mikel authored
415 set_payload_for_mail(payload, mail)
e10f51b @josevalim Refactor delivery methods.
josevalim authored
416
417 # TODO Move me to the instance
418 mail.delivery_method delivery_methods[delivery_method],
419 delivery_settings[delivery_method]
420
0750304 @mikel Migrated over to Mail doing delivery.
mikel authored
421 if @@perform_deliveries
422 mail.deliver!
423 self.deliveries << mail
424 end
425 end
426 rescue Exception => e # Net::SMTP errors or sendmail pipe errors
427 raise e if raise_delivery_errors
428 end
429
430 mail
431 end
432
cb21db1 @josh Treat ActionMailer template_root as a view path set internally to avo…
josh authored
433 def template_root
434 self.view_paths && self.view_paths.first
435 end
436
684c2dc @josevalim Remove ActionMailer helpers and rely on AbstractController one.
josevalim authored
437 # Should template root overwrite the whole view_paths?
61c90a4 @NZKoz Reapply the TemplateFinder first applied in [8669] then reverted in […
NZKoz authored
438 def template_root=(root)
cb21db1 @josh Treat ActionMailer template_root as a view path set internally to avo…
josh authored
439 self.view_paths = ActionView::Base.process_view_paths(root)
61c90a4 @NZKoz Reapply the TemplateFinder first applied in [8669] then reverted in […
NZKoz authored
440 end
3cf773b @floehopper ActionMailer should respond_to? to methods handled by method_missing …
floehopper authored
441
704daad @josevalim Ensure we just send Ruby Stdlib objects in ActionMailer notifications.
josevalim authored
442 def set_payload_for_mail(payload, mail) #:nodoc:
c905fce @josevalim Add message_id to AM payload and don't send bcc and cc if they were n…
josevalim authored
443 payload[:message_id] = mail.message_id
444 payload[:subject] = mail.subject
445 payload[:to] = mail.to
446 payload[:from] = mail.from
447 payload[:bcc] = mail.bcc if mail.bcc.present?
448 payload[:cc] = mail.cc if mail.cc.present?
449 payload[:date] = mail.date
450 payload[:mail] = mail.encoded
704daad @josevalim Ensure we just send Ruby Stdlib objects in ActionMailer notifications.
josevalim authored
451 end
452
3cf773b @floehopper ActionMailer should respond_to? to methods handled by method_missing …
floehopper authored
453 private
c8e2998 @mikel First pass on fixing delivery method
mikel authored
454
3cf773b @floehopper ActionMailer should respond_to? to methods handled by method_missing …
floehopper authored
455 def matches_dynamic_method?(method_name) #:nodoc:
456 method_name = method_name.to_s
c65075f @mocoso Fixed method_missing for ActionMailer so it no longer matches methods…
mocoso authored
457 /^(create|deliver)_([_a-z]\w*)/.match(method_name) || /^(new)$/.match(method_name)
3cf773b @floehopper ActionMailer should respond_to? to methods handled by method_missing …
floehopper authored
458 end
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but …
jamis authored
459 end
460
971f4ff @josevalim DRY ActionMailer code.
josevalim authored
461 # Add a part to a multipart message, with the given content-type. The
462 # part itself is yielded to the block so that other properties (charset,
463 # body, headers, etc.) can be set on it.
464 def part(params)
465 params = {:content_type => params} if String === params
f00cbf7 @josevalim Bring render_message back for 2.3 compatibility.
josevalim authored
466
971f4ff @josevalim DRY ActionMailer code.
josevalim authored
467 if custom_headers = params.delete(:headers)
468 ActiveSupport::Deprecation.warn('Passing custom headers with :headers => {} is deprecated. ' <<
469 'Please just pass in custom headers directly.', caller[0,10])
470 params.merge!(custom_headers)
471 end
f00cbf7 @josevalim Bring render_message back for 2.3 compatibility.
josevalim authored
472
971f4ff @josevalim DRY ActionMailer code.
josevalim authored
473 part = Mail::Part.new(params)
474 yield part if block_given?
475 @parts << part
476 end
477
478 # Add an attachment to a multipart message. This is simply a part with the
479 # content-disposition set to "attachment".
480 def attachment(params, &block)
481 super # Run deprecation hooks
482
483 params = { :content_type => params } if String === params
484 params = { :content_disposition => "attachment",
485 :content_transfer_encoding => "base64" }.merge(params)
486
487 part(params, &block)
488 end
489
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
490 # Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer
491 # will be initialized according to the named method. If not, the mailer will
492 # remain uninitialized (useful when you only need to invoke the "receive"
493 # method, for instance).
971f4ff @josevalim DRY ActionMailer code.
josevalim authored
494 def initialize(method_name=nil, *args)
d887e46 @jeremy Be sure to invoke the super chain! And initialize response body.
jeremy authored
495 super()
4964d3b @josevalim Make ActionMailer::Base inherit from AbstractController::Base
josevalim authored
496 process(method_name, *args) if method_name
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
497 end
498
4964d3b @josevalim Make ActionMailer::Base inherit from AbstractController::Base
josevalim authored
499 # Process the mailer via the given +method_name+. The body will be
971f4ff @josevalim DRY ActionMailer code.
josevalim authored
500 # rendered and a new Mail object created.
501 def process(method_name, *args)
43d5504 @josevalim Move all render and layout pieces required in ActionMailer from Actio…
josevalim authored
502 initialize_defaults(method_name)
4964d3b @josevalim Make ActionMailer::Base inherit from AbstractController::Base
josevalim authored
503 super
43d5504 @josevalim Move all render and layout pieces required in ActionMailer from Actio…
josevalim authored
504
418c3f8 @josevalim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
505 # Create e-mail parts
506 create_parts
09f798b @josevalim Instrument create and deliver in ActionMailer.
josevalim authored
507
2aafdc8 @josevalim Use I18n on ActionMailer subjects by default.
josevalim authored
508 # Set the subject if not set yet
4a1f438 @josevalim Change mailer subjects lookup.
josevalim authored
509 @subject ||= I18n.t(:subject, :scope => [:actionmailer, mailer_name, method_name],
510 :default => method_name.humanize)
43d5504 @josevalim Move all render and layout pieces required in ActionMailer from Actio…
josevalim authored
511
4964d3b @josevalim Make ActionMailer::Base inherit from AbstractController::Base
josevalim authored
512 # Build the mail object itself
88ba056 @josevalim Refactor multiple parts logic and move Utils to PartContainer.
josevalim authored
513 create_mail
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
514 end
db045db @dhh Initial
dhh authored
515
15d7cac @mikel Starting again on actionmailer integration with mail
mikel authored
516 # Delivers a Mail object. By default, it delivers the cached mail
98dc582 @lifo Merge docrails.
lifo authored
517 # object (from the <tt>create!</tt> method). If no cached mail object exists, and
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but …
jamis authored
518 # no alternate has been given as the parameter, this will fail.
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
519 def deliver!(mail = @mail)
0750304 @mikel Migrated over to Mail doing delivery.
mikel authored
520 self.class.deliver(mail)
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
521 end
3fad0cd @dhh Added support for charsets for both subject and body. The default cha…
dhh authored
522
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
523 private
418c3f8 @josevalim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
524
f00cbf7 @josevalim Bring render_message back for 2.3 compatibility.
josevalim authored
525 # Render a message but does not set it as mail body. Useful for rendering
526 # data for part and attachments.
a037458 @josevalim Bring body(Hash) behavior back.
josevalim authored
527 #
f00cbf7 @josevalim Bring render_message back for 2.3 compatibility.
josevalim authored
528 # Examples:
a037458 @josevalim Bring body(Hash) behavior back.
josevalim authored
529 #
f00cbf7 @josevalim Bring render_message back for 2.3 compatibility.
josevalim authored
530 # render_message "special_message"
531 # render_message :template => "special_message"
532 # render_message :inline => "<%= 'Hi!' %>"
e10f51b @josevalim Refactor delivery methods.
josevalim authored
533 #
534 # TODO Deprecate me
f00cbf7 @josevalim Bring render_message back for 2.3 compatibility.
josevalim authored
535 def render_message(object)
536 case object
537 when String
538 render_to_body(:template => object)
539 else
540 render_to_body(object)
a037458 @josevalim Bring body(Hash) behavior back.
josevalim authored
541 end
542 end
543
f474f33 @jamis Move mailer initialization to a separate (overridable) method, so tha…
jamis authored
544 # Set up the default values for the various instance variables of this
545 # mailer. Subclasses may override this method to provide different
546 # defaults.
971f4ff @josevalim DRY ActionMailer code.
josevalim authored
547 def initialize_defaults(method_name) #:nodoc:
81c416b @josevalim More refactoring on ActionMailer::Base.
josevalim authored
548 @charset ||= @@default_charset.dup
549 @content_type ||= @@default_content_type.dup
95e8740 @dhh Allow Mailers to have custom initialize methods that set default inst…
dhh authored
550 @implicit_parts_order ||= @@default_implicit_parts_order.dup
81c416b @josevalim More refactoring on ActionMailer::Base.
josevalim authored
551 @mime_version ||= @@default_mime_version.dup if @@default_mime_version
552
4964d3b @josevalim Make ActionMailer::Base inherit from AbstractController::Base
josevalim authored
553 @mailer_name ||= self.class.mailer_name.dup
0750304 @mikel Migrated over to Mail doing delivery.
mikel authored
554 @delivery_method = self.class.delivery_method
81c416b @josevalim More refactoring on ActionMailer::Base.
josevalim authored
555 @template ||= method_name
556
557 @parts ||= []
95e8740 @dhh Allow Mailers to have custom initialize methods that set default inst…
dhh authored
558 @headers ||= {}
5fdc33c @mrduncan Default sent_on time to now in ActionMailer
mrduncan authored
559 @sent_on ||= Time.now
f474f33 @jamis Move mailer initialization to a separate (overridable) method, so tha…
jamis authored
560
4964d3b @josevalim Make ActionMailer::Base inherit from AbstractController::Base
josevalim authored
561 super # Run deprecation hooks
6228220 @dhh Revert "Revert "Add layout functionality to mailers.""
dhh authored
562 end
563
971f4ff @josevalim DRY ActionMailer code.
josevalim authored
564 def create_parts #:nodoc:
4964d3b @josevalim Make ActionMailer::Base inherit from AbstractController::Base
josevalim authored
565 super # Run deprecation hooks
cb21db1 @josh Treat ActionMailer template_root as a view path set internally to avo…
josh authored
566
418c3f8 @josevalim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
567 if String === response_body
971f4ff @josevalim DRY ActionMailer code.
josevalim authored
568 @parts.unshift create_inline_part(response_body)
418c3f8 @josevalim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
569 else
616ebb8 @josevalim Remove unused code paths and require mail only when it's needed.
josevalim authored
570 self.class.template_root.find_all(@template, {}, @mailer_name).each do |template|
971f4ff @josevalim DRY ActionMailer code.
josevalim authored
571 @parts << create_inline_part(render_to_body(:_template => template), template.mime_type)
418c3f8 @josevalim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
572 end
cb21db1 @josh Treat ActionMailer template_root as a view path set internally to avo…
josh authored
573
418c3f8 @josevalim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
574 if @parts.size > 1
575 @content_type = "multipart/alternative" if @content_type !~ /^multipart/
576 end
2aafdc8 @josevalim Use I18n on ActionMailer subjects by default.
josevalim authored
577
578 # If this is a multipart e-mail add the mime_version if it is not
579 # already set.
580 @mime_version ||= "1.0" if !@parts.empty?
418c3f8 @josevalim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
581 end
db045db @dhh Initial
dhh authored
582 end
583
971f4ff @josevalim DRY ActionMailer code.
josevalim authored
584 def create_inline_part(body, mime_type=nil) #:nodoc:
585 ct = mime_type || "text/plain"
586 main_type, sub_type = split_content_type(ct.to_s)
587
588 Mail::Part.new(
589 :content_type => [main_type, sub_type, {:charset => charset}],
590 :content_disposition => "inline",
591 :body => body
592 )
593 end
594
595 def create_mail #:nodoc:
15d7cac @mikel Starting again on actionmailer integration with mail
mikel authored
596 m = Mail.new
74a612c @dhh Added that delivery errors are caught in a way so the mail is still r…
dhh authored
597
cf6299d Add ActionMailer#reply_to. [#245 state:resolved]
Adam authored
598 m.subject, = quote_any_if_necessary(charset, subject)
599 m.to, m.from = quote_any_address_if_necessary(charset, recipients, from)
600 m.bcc = quote_address_if_necessary(bcc, charset) unless bcc.nil?
601 m.cc = quote_address_if_necessary(cc, charset) unless cc.nil?
602 m.reply_to = quote_address_if_necessary(reply_to, charset) unless reply_to.nil?
dca4d4e @jamis Multipart messages specify a MIME-Version header automatically #2003 …
jamis authored
603 m.mime_version = mime_version unless mime_version.nil?
cf6299d Add ActionMailer#reply_to. [#245 state:resolved]
Adam authored
604 m.date = sent_on.to_time rescue sent_on if sent_on
605
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
606 headers.each { |k, v| m[k] = v }
db045db @dhh Initial
dhh authored
607
db0e8ff @jamis Parse content-type apart before using it so that sub-parts of the hea…
jamis authored
608 real_content_type, ctype_attrs = parse_content_type
971f4ff @josevalim DRY ActionMailer code.
josevalim authored
609 main_type, sub_type = split_content_type(real_content_type)
5d9af09 @josh Silence known internal AM deprecation calls
josh authored
610
616ebb8 @josevalim Remove unused code paths and require mail only when it's needed.
josevalim authored
611 if @parts.size == 1 && @parts.first.parts.empty?
a5e6295 @mikel Down to 30 failures total
mikel authored
612 m.content_type([main_type, sub_type, ctype_attrs])
a6eed86 @mikel Removing utils, and updating requires to match
mikel authored
613 m.body = @parts.first.body.encoded
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
614 else
615 @parts.each do |p|
747d568 @mikel 131 tests, 309 assertions, 0 failures, 0 errors
mikel authored
616 m.add_part(p)
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
617 end
616ebb8 @josevalim Remove unused code paths and require mail only when it's needed.
josevalim authored
618
c039bcd @mikel Moved sort_parts into Mail, updated mail requirement to 1.4.2
mikel authored
619 m.body.set_sort_order(@implicit_parts_order)
620 m.body.sort_parts!
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
621
49efa02 @jamis Nil charset caused subject line to be improperly quoted in implicitly…
jamis authored
622 if real_content_type =~ /multipart/
623 ctype_attrs.delete "charset"
a5e6295 @mikel Down to 30 failures total
mikel authored
624 m.content_type([main_type, sub_type, ctype_attrs])
49efa02 @jamis Nil charset caused subject line to be improperly quoted in implicitly…
jamis authored
625 end
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
626 end
256e800 @dhh Fixed quoting for all address headers, not just to #955 [Jamis Buck] …
dhh authored
627
b354496 @mikel Adding default 8bit encoding if the body has non usascii in it
mikel authored
628 m.content_transfer_encoding = '8bit' unless m.body.only_us_ascii?
629
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
630 @mail = m
256e800 @dhh Fixed quoting for all address headers, not just to #955 [Jamis Buck] …
dhh authored
631 end
539d9b3 @mikel More updates... 45 errors left to get it working with Mail gem
mikel authored
632
971f4ff @josevalim DRY ActionMailer code.
josevalim authored
633 def split_content_type(ct) #:nodoc:
539d9b3 @mikel More updates... 45 errors left to get it working with Mail gem
mikel authored
634 ct.to_s.split("/")
635 end
256e800 @dhh Fixed quoting for all address headers, not just to #955 [Jamis Buck] …
dhh authored
636
971f4ff @josevalim DRY ActionMailer code.
josevalim authored
637 def parse_content_type(defaults=nil) #:nodoc:
616ebb8 @josevalim Remove unused code paths and require mail only when it's needed.
josevalim authored
638 if @content_type.blank?
639 [ nil, {} ]
971f4ff @josevalim DRY ActionMailer code.
josevalim authored
640 else
616ebb8 @josevalim Remove unused code paths and require mail only when it's needed.
josevalim authored
641 ctype, *attrs = @content_type.split(/;\s*/)
971f4ff @josevalim DRY ActionMailer code.
josevalim authored
642 attrs = attrs.inject({}) { |h,s| k,v = s.split(/\=/, 2); h[k] = v; h }
616ebb8 @josevalim Remove unused code paths and require mail only when it's needed.
josevalim authored
643 [ctype, {"charset" => @charset}.merge(attrs)]
971f4ff @josevalim DRY ActionMailer code.
josevalim authored
644 end
15d7cac @mikel Starting again on actionmailer integration with mail
mikel authored
645 end
646
db045db @dhh Initial
dhh authored
647 end
648 end
Something went wrong with that request. Please try again.