Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 680 lines (597 sloc) 27.311 kb
a9751a7 @josevalim Refactor ActionMailer layout and remove legacy one.
josevalim authored
1 require 'active_support/core_ext/class'
a63caa4 Get tests to run (with failures) without old base around
Yehuda Katz + Carl Lerche authored
2
c4590d5 @dhh Fixed docs
dhh authored
3 module ActionMailer #:nodoc:
98dc582 @lifo Merge docrails.
lifo authored
4 # Action Mailer allows you to send email from your application using a mailer model and views.
db045db @dhh Initial
dhh authored
5 #
20bd4bd @dhh Updated docs and otherwise
dhh authored
6 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
7 # = Mailer Models
20bd4bd @dhh Updated docs and otherwise
dhh authored
8 #
98dc582 @lifo Merge docrails.
lifo authored
9 # To use Action Mailer, you need to create a mailer model.
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
10 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
11 # $ script/generate mailer Notifier
12 #
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
13 # The generated model inherits from ActionMailer::Base. Emails are defined by creating methods within the model which are then
14 # 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, Mar...
Marcel Molina authored
15 # to add attachments.
16 #
17 # Examples:
18 #
19 # class Notifier < ActionMailer::Base
20 # def signup_notification(recipient)
21 # recipients recipient.email_address_with_name
c3f53f4 @lifo Merge docrails
lifo authored
22 # bcc ["bcc@example.com", "Order Watcher <watcher@example.com>"]
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
23 # from "system@example.com"
24 # subject "New account information"
20bd4bd @dhh Updated docs and otherwise
dhh authored
25 # body :account => recipient
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
26 # end
27 # end
28 #
29 # Mailer methods have the following configuration methods available.
30 #
31 # * <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.
32 # * <tt>subject</tt> - The subject of your email. Sets the <tt>Subject:</tt> header.
33 # * <tt>from</tt> - Who the email you are sending is from. Sets the <tt>From:</tt> header.
34 # * <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
35 # * <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.
36 # * <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.
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
37 # * <tt>sent_on</tt> - The date on which the message was sent. If not set, the header wil be set by the delivery agent.
38 # * <tt>content_type</tt> - Specify the content type of the message. Defaults to <tt>text/plain</tt>.
39 # * <tt>headers</tt> - Specify additional headers to be set for the message, e.g. <tt>headers 'X-Mail-Count' => 107370</tt>.
40 #
5c0d38f @dhh Fixed that a return-path header would be ignored (closes #7572) [joost]
dhh authored
41 # When a <tt>headers 'return-path'</tt> is specified, that value will be used as the 'envelope from'
42 # address. Setting this is useful when you want delivery notifications sent to a different address than
43 # the one in <tt>from</tt>.
44 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
45 # The <tt>body</tt> method has special behavior. It takes a hash which generates an instance variable
46 # named after each key in the hash containing the value that that key points to.
47 #
5c0d38f @dhh Fixed that a return-path header would be ignored (closes #7572) [joost]
dhh authored
48 # So, for example, <tt>body :account => recipient</tt> would result
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
49 # in an instance variable <tt>@account</tt> with the value of <tt>recipient</tt> being accessible in the
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
50 # view.
51 #
20bd4bd @dhh Updated docs and otherwise
dhh authored
52 #
53 # = Mailer views
54 #
98dc582 @lifo Merge docrails.
lifo authored
55 # Like Action Controller, each mailer class has a corresponding view directory
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
56 # in which each method of the class looks for a template with its name.
21187c0 @dhh Apply the rest of Chads patch
dhh authored
57 # 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 Inflect...
josh authored
58 # in your mailer model. For example, in the mailer defined above, the template at
21187c0 @dhh Apply the rest of Chads patch
dhh authored
59 # <tt>app/views/notifier/signup_notification.erb</tt> would be used to generate the email.
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
60 #
61 # Variables defined in the model are accessible as instance variables in the view.
62 #
63 # Emails by default are sent in plain text, so a sample view for our model example might look like this:
64 #
65 # Hi <%= @account.name %>,
66 # Thanks for joining our service! Please check back often.
67 #
20bd4bd @dhh Updated docs and otherwise
dhh authored
68 # You can even use Action Pack helpers in these views. For example:
69 #
70 # You got a new note!
71 # <%= truncate(note.body, 25) %>
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
72 #
20bd4bd @dhh Updated docs and otherwise
dhh authored
73 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
74 # = Generating URLs
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
75 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
76 # 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 Inflect...
josh authored
77 # Unlike controllers from Action Pack, the mailer instance doesn't have any context about the incoming request,
78 # so you'll need to provide all of the details needed to generate a URL.
20bd4bd @dhh Updated docs and otherwise
dhh authored
79 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
80 # 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 Inflect...
josh authored
81 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
82 # <%= url_for(:host => "example.com", :controller => "welcome", :action => "greeting") %>
20bd4bd @dhh Updated docs and otherwise
dhh authored
83 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
84 # When using named routes you only need to supply the <tt>:host</tt>:
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
85 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
86 # <%= users_url(:host => "example.com") %>
87 #
88 # You will want to avoid using the <tt>name_of_route_path</tt> form of named routes because it doesn't make sense to
89 # generate relative URLs in email messages.
90 #
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
91 # 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
92 # the <tt>ActionMailer::Base.default_url_options</tt> hash as follows:
93 #
94 # ActionMailer::Base.default_url_options[:host] = "example.com"
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
95 #
dc4eec1 @lifo Merge docrails:
lifo authored
96 # 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
97 #
98 # config.action_mailer.default_url_options = { :host => "example.com" }
20bd4bd @dhh Updated docs and otherwise
dhh authored
99 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
100 # If you do decide to set a default <tt>:host</tt> for your mailers you will want to use the
101 # <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 Inflect...
josh authored
102 # 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
103 # explicitly provided.
20bd4bd @dhh Updated docs and otherwise
dhh authored
104 #
105 # = Sending mail
106 #
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
107 # 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, Mar...
Marcel Molina authored
108 # for delivery later:
109 #
110 # Notifier.deliver_signup_notification(david) # sends the email
111 # mail = Notifier.create_signup_notification(david) # => a tmail object
112 # Notifier.deliver(mail)
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
113 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
114 # You never instantiate your mailer class. Rather, your delivery instance
115 # methods are automatically wrapped in class methods that start with the word
116 # <tt>deliver_</tt> followed by the name of the mailer method that you would
117 # like to deliver. The <tt>signup_notification</tt> method defined above is
118 # delivered by invoking <tt>Notifier.deliver_signup_notification</tt>.
119 #
20bd4bd @dhh Updated docs and otherwise
dhh authored
120 #
121 # = HTML email
122 #
21187c0 @dhh Apply the rest of Chads patch
dhh authored
123 # 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, Mar...
Marcel Molina authored
124 # set the content type to html.
125 #
126 # class MyMailer < ActionMailer::Base
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
127 # def signup_notification(recipient)
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored
128 # recipients recipient.email_address_with_name
129 # subject "New account information"
130 # from "system@example.com"
131 # body :account => recipient
132 # content_type "text/html"
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
133 # end
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
134 # end
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
135 #
20bd4bd @dhh Updated docs and otherwise
dhh authored
136 #
137 # = Multipart email
138 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
139 # You can explicitly specify multipart messages:
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
140 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
141 # class ApplicationMailer < ActionMailer::Base
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
142 # def signup_notification(recipient)
143 # recipients recipient.email_address_with_name
144 # subject "New account information"
145 # from "system@example.com"
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored
146 # content_type "multipart/alternative"
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
147 #
148 # part :content_type => "text/html",
149 # :body => render_message("signup-as-html", :account => recipient)
150 #
151 # part "text/plain" do |p|
152 # p.body = render_message("signup-as-plain", :account => recipient)
153 # p.transfer_encoding = "base64"
154 # end
155 # end
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
156 # end
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
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, Mar...
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 Inflect...
josh authored
161 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
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 Inflect...
josh authored
167 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
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 and ...
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, Mar...
Marcel Molina authored
178 # = Attachments
20bd4bd @dhh Updated docs and otherwise
dhh authored
179 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
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 and ...
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 Inflect...
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 cach...
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/disablin...
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 classes...
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 cach...
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/disablin...
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 cach...
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/disablin...
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/disablin...
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 sorting...
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 sorting...
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+.
db045db @dhh Initial
dhh authored
253 class Base
e201fc7 @josh use autoload instead of explicit requires for ActionMailer
josh authored
254 include AdvAttrAccessor, PartContainer, Quoting, Utils
a9751a7 @josevalim Refactor ActionMailer layout and remove legacy one.
josevalim authored
255
256 include AbstractController::RenderingController
257 include AbstractController::Layouts
09f798b @josevalim Instrument create and deliver in ActionMailer.
josevalim authored
258
684c2dc @josevalim Remove ActionMailer helpers and rely on AbstractController one.
josevalim authored
259 include AbstractController::Helpers
260 helper MailHelper
261
6228220 @dhh Revert "Revert "Add layout functionality to mailers.""
dhh authored
262 if Object.const_defined?(:ActionController)
263 include ActionController::UrlWriter
264 end
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
265
c927aa0 @dhh Updated documentation
dhh authored
266 private_class_method :new #:nodoc:
db045db @dhh Initial
dhh authored
267
cb21db1 @josh Treat ActionMailer template_root as a view path set internally to avoid ...
josh authored
268 class_inheritable_accessor :view_paths
441e4e2 @svenfuchs load plugin view_paths to action_mailer view_paths and make action_maile...
svenfuchs authored
269 self.view_paths = []
270
db045db @dhh Initial
dhh authored
271 cattr_accessor :logger
272
f4f7677 @matthewrudy abstract all of the ActionMailer delivery methods into their own classes...
matthewrudy authored
273 class << self
274 delegate :settings, :settings=, :to => ActionMailer::DeliveryMethod::File, :prefix => :file
275 delegate :settings, :settings=, :to => ActionMailer::DeliveryMethod::Sendmail, :prefix => :sendmail
276 delegate :settings, :settings=, :to => ActionMailer::DeliveryMethod::Smtp, :prefix => :smtp
277
278 def delivery_method=(method_name)
279 @delivery_method = ActionMailer::DeliveryMethod.lookup_method(method_name)
280 end
281 end
282 self.delivery_method = :smtp
283 superclass_delegating_reader :delivery_method
fbe6c3c @edavis10 Adds a :file delivery_method to save email to a file on disk
edavis10 authored
284
db045db @dhh Initial
dhh authored
285 @@raise_delivery_errors = true
286 cattr_accessor :raise_delivery_errors
287
288 @@perform_deliveries = true
289 cattr_accessor :perform_deliveries
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
290
db045db @dhh Initial
dhh authored
291 @@deliveries = []
292 cattr_accessor :deliveries
293
3fad0cd @dhh Added support for charsets for both subject and body. The default charse...
dhh authored
294 @@default_charset = "utf-8"
295 cattr_accessor :default_charset
296
100fd72 @jamis Added a "content_type" accessor to allow messages to explicitly specify ...
jamis authored
297 @@default_content_type = "text/plain"
298 cattr_accessor :default_content_type
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
299
45b5555 @jamis Make mime version default to 1.0. closes #2323
jamis authored
300 @@default_mime_version = "1.0"
dca4d4e @jamis Multipart messages specify a MIME-Version header automatically #2003 [Jo...
jamis authored
301 cattr_accessor :default_mime_version
100fd72 @jamis Added a "content_type" accessor to allow messages to explicitly specify ...
jamis authored
302
5c98152 @jamis Better multipart support with implicit multipart/alternative and sorting...
jamis authored
303 @@default_implicit_parts_order = [ "text/html", "text/enriched", "text/plain" ]
304 cattr_accessor :default_implicit_parts_order
305
28bf2fa @josh Protect body ivar from being clobbered by the mailer template assigns
josh authored
306 cattr_reader :protected_instance_variables
307 @@protected_instance_variables = %w(@body)
308
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
309 # Specify the BCC addresses for the message
310 adv_attr_accessor :bcc
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
311
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
312 # Define the body of the message. This is either a Hash (in which case it
313 # specifies the variables to pass to the template when it is rendered),
314 # or a string, in which case it specifies the actual text of the message.
315 adv_attr_accessor :body
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
316
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
317 # Specify the CC addresses for the message.
318 adv_attr_accessor :cc
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
319
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
320 # Specify the charset to use for the message. This defaults to the
321 # +default_charset+ specified for ActionMailer::Base.
322 adv_attr_accessor :charset
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
323
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
324 # Specify the content type for the message. This defaults to <tt>text/plain</tt>
325 # in most cases, but can be automatically set in some situations.
326 adv_attr_accessor :content_type
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
327
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
328 # Specify the from address for the message.
329 adv_attr_accessor :from
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
330
cf6299d Add ActionMailer#reply_to. [#245 state:resolved]
Adam authored
331 # Specify the address (if different than the "from" address) to direct
332 # replies to this message.
333 adv_attr_accessor :reply_to
334
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
335 # Specify additional headers to be added to the message.
336 adv_attr_accessor :headers
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
337
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
338 # Specify the order in which parts should be sorted, based on content-type.
339 # This defaults to the value for the +default_implicit_parts_order+.
340 adv_attr_accessor :implicit_parts_order
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
341
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
342 # Defaults to "1.0", but may be explicitly given if needed.
343 adv_attr_accessor :mime_version
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
344
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
345 # The recipient addresses for the message, either as a string (for a single
346 # address) or an array (for multiple addresses).
347 adv_attr_accessor :recipients
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
348
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
349 # The date on which the message was sent. If not set (the default), the
350 # header will be set by the delivery agent.
351 adv_attr_accessor :sent_on
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
352
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
353 # Specify the subject of the message.
354 adv_attr_accessor :subject
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
355
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
356 # Specify the template name to use for current message. This is the "base"
357 # template name, without the extension or directory, and may be used to
358 # have multiple mailer methods share the same template.
359 adv_attr_accessor :template
165097e @dhh Added access to custom headers, like cc, bcc, and reply-to #268 [Andreas...
dhh authored
360
bd5ed65 @technoweenie Update ActionMailer so it treats ActionView the same way that ActionCont...
technoweenie authored
361 # Override the mailer name, which defaults to an inflected version of the
362 # mailer's class name. If you want to use a template in a non-standard
363 # location, you can use this to specify that location.
364 def mailer_name(value = nil)
365 if value
366 self.mailer_name = value
367 else
368 self.class.mailer_name
369 end
370 end
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
371
bd5ed65 @technoweenie Update ActionMailer so it treats ActionView the same way that ActionCont...
technoweenie authored
372 def mailer_name=(value)
373 self.class.mailer_name = value
374 end
375
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
376 # The mail object instance referenced by this mailer.
377 attr_reader :mail
6228220 @dhh Revert "Revert "Add layout functionality to mailers.""
dhh authored
378 attr_reader :template_name, :default_template_name, :action_name
43d5504 @josevalim Move all render and layout pieces required in ActionMailer from ActionCo...
josevalim authored
379 attr_internal :response_body
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
380
eb9af20 @wycats Begin unifying the interface between ActionController and ActionView
wycats authored
381 def controller_path
382 self.class.controller_path
383 end
43d5504 @josevalim Move all render and layout pieces required in ActionMailer from ActionCo...
josevalim authored
384
eb9af20 @wycats Begin unifying the interface between ActionController and ActionView
wycats authored
385 def formats
43d5504 @josevalim Move all render and layout pieces required in ActionMailer from ActionCo...
josevalim authored
386 [:"*/*"]
387 end
388
389 # Refactor out all mailer_name
390 def _prefix
391 mailer_name
eb9af20 @wycats Begin unifying the interface between ActionController and ActionView
wycats authored
392 end
393
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but was...
jamis authored
394 class << self
bd5ed65 @technoweenie Update ActionMailer so it treats ActionView the same way that ActionCont...
technoweenie authored
395 attr_writer :mailer_name
396
397 def mailer_name
398 @mailer_name ||= name.underscore
399 end
400
401 # for ActionView compatibility
402 alias_method :controller_name, :mailer_name
403 alias_method :controller_path, :mailer_name
404
3cf773b @floehopper ActionMailer should respond_to? to methods handled by method_missing [#7...
floehopper authored
405 def respond_to?(method_symbol, include_private = false) #:nodoc:
406 matches_dynamic_method?(method_symbol) || super
407 end
408
409 def method_missing(method_symbol, *parameters) #:nodoc:
a62e9e9 @mocoso Fix for ActionMailer::Base.method_missing so that it raises NoMethodErro...
mocoso authored
410 if match = matches_dynamic_method?(method_symbol)
411 case match[1]
412 when 'create' then new(match[2], *parameters).mail
413 when 'deliver' then new(match[2], *parameters).deliver!
414 when 'new' then nil
c65075f @mocoso Fixed method_missing for ActionMailer so it no longer matches methods wh...
mocoso authored
415 else super
a62e9e9 @mocoso Fix for ActionMailer::Base.method_missing so that it raises NoMethodErro...
mocoso authored
416 end
417 else
418 super
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but was...
jamis authored
419 end
420 end
421
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
422 # Receives a raw email, parses it into an email object, decodes it,
423 # instantiates a new mailer, and passes the email object to the mailer
98dc582 @lifo Merge docrails.
lifo authored
424 # object's +receive+ method. If you want your mailer to be able to
425 # process incoming messages, you'll need to implement a +receive+
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
426 # method that accepts the email object as a parameter:
427 #
428 # class MyMailer < ActionMailer::Base
429 # def receive(mail)
430 # ...
431 # end
432 # end
433 def receive(raw_email)
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but was...
jamis authored
434 logger.info "Received mail:\n #{raw_email}" unless logger.nil?
435 mail = TMail::Mail.parse(raw_email)
436 mail.base64_decode
437 new.receive(mail)
438 end
439
440 # Deliver the given mail object directly. This can be used to deliver
441 # a preconstructed mail object, like:
442 #
443 # email = MyMailer.create_some_mail(parameters)
444 # email.set_some_obscure_header "frobnicate"
445 # MyMailer.deliver(email)
446 def deliver(mail)
447 new.deliver!(mail)
448 end
271404e @jeremy Register alternative template engines using ActionMailer::Base.register_...
jeremy authored
449
cb21db1 @josh Treat ActionMailer template_root as a view path set internally to avoid ...
josh authored
450 def template_root
451 self.view_paths && self.view_paths.first
452 end
453
684c2dc @josevalim Remove ActionMailer helpers and rely on AbstractController one.
josevalim authored
454 # Should template root overwrite the whole view_paths?
61c90a4 @NZKoz Reapply the TemplateFinder first applied in [8669] then reverted in [867...
NZKoz authored
455 def template_root=(root)
cb21db1 @josh Treat ActionMailer template_root as a view path set internally to avoid ...
josh authored
456 self.view_paths = ActionView::Base.process_view_paths(root)
61c90a4 @NZKoz Reapply the TemplateFinder first applied in [8669] then reverted in [867...
NZKoz authored
457 end
3cf773b @floehopper ActionMailer should respond_to? to methods handled by method_missing [#7...
floehopper authored
458
459 private
460 def matches_dynamic_method?(method_name) #:nodoc:
461 method_name = method_name.to_s
c65075f @mocoso Fixed method_missing for ActionMailer so it no longer matches methods wh...
mocoso authored
462 /^(create|deliver)_([_a-z]\w*)/.match(method_name) || /^(new)$/.match(method_name)
3cf773b @floehopper ActionMailer should respond_to? to methods handled by method_missing [#7...
floehopper authored
463 end
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but was...
jamis authored
464 end
465
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
466 # Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer
467 # will be initialized according to the named method. If not, the mailer will
468 # remain uninitialized (useful when you only need to invoke the "receive"
469 # method, for instance).
2789b5d @dhh Tuned documentation for release (AM)
dhh authored
470 def initialize(method_name=nil, *parameters) #:nodoc:
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
471 create!(method_name, *parameters) if method_name
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
472 end
473
474 # Initialize the mailer via the given +method_name+. The body will be
475 # rendered and a new TMail::Mail object created.
2789b5d @dhh Tuned documentation for release (AM)
dhh authored
476 def create!(method_name, *parameters) #:nodoc:
43d5504 @josevalim Move all render and layout pieces required in ActionMailer from ActionCo...
josevalim authored
477 initialize_defaults(method_name)
478 __send__(method_name, *parameters)
479
480 # Check if render was called.
481 @body = self.response_body if @body.is_a?(Hash) && @body.empty?
09f798b @josevalim Instrument create and deliver in ActionMailer.
josevalim authored
482
43d5504 @josevalim Move all render and layout pieces required in ActionMailer from ActionCo...
josevalim authored
483 # If an explicit, textual body has not been set, we check assumptions.
484 unless String === @body
485 # TODO Fix me. Deprecate assigns to be given as a :body hash
486 if @body.is_a?(Hash)
684c2dc @josevalim Remove ActionMailer helpers and rely on AbstractController one.
josevalim authored
487 @body.each do |k, v|
488 instance_variable_set(:"@#{k}", v)
489 end
09f798b @josevalim Instrument create and deliver in ActionMailer.
josevalim authored
490 end
db045db @dhh Initial
dhh authored
491
43d5504 @josevalim Move all render and layout pieces required in ActionMailer from ActionCo...
josevalim authored
492 # First, we look to see if there are any likely templates that match,
493 # which include the content-type in their file name (i.e.,
494 # "the_template_file.text.html.erb", etc.). Only do this if parts
495 # have not already been specified manually.
496 # if @parts.empty?
497 template_root.find_all(@template, {}, template_path).each do |template|
498 @parts << Part.new(
499 :content_type => template.mime_type ? template.mime_type.to_s : "text/plain",
500 :disposition => "inline",
501 :charset => charset,
502 :body => render_to_body(:_template => template)
503 )
504 end
dca4d4e @jamis Multipart messages specify a MIME-Version header automatically #2003 [Jo...
jamis authored
505
43d5504 @josevalim Move all render and layout pieces required in ActionMailer from ActionCo...
josevalim authored
506 if @parts.size > 1
507 @content_type = "multipart/alternative" if @content_type !~ /^multipart/
508 @parts = sort_parts(@parts, @implicit_parts_order)
509 end
510 # end
511
512 # Then, if there were such templates, we check to see if we ought to
513 # also render a "normal" template (without the content type). If a
514 # normal template exists (or if there were no implicit parts) we render
515 # it.
516 # ====
517 # TODO: Revisit this
518 # template_exists = @parts.empty?
519 # template_exists ||= template_root.find("#{mailer_name}/#{@template}")
520 # @body = render_message(@template, @body) if template_exists
521
522 # Finally, if there are other message parts and a textual body exists,
523 # we shift it onto the front of the parts and set the body to nil (so
524 # that create_mail doesn't try to render it in addition to the parts).
525 # ====
526 # TODO: Revisit this
527 # if !@parts.empty? && String === @body
528 # @parts.unshift Part.new(:charset => charset, :body => @body)
529 # @body = nil
530 # end
09f798b @josevalim Instrument create and deliver in ActionMailer.
josevalim authored
531 end
532
43d5504 @josevalim Move all render and layout pieces required in ActionMailer from ActionCo...
josevalim authored
533 # If this is a multipart e-mail add the mime_version if it is not
534 # already set.
535 @mime_version ||= "1.0" if !@parts.empty?
536
537 # build the mail object itself
538 @mail = create_mail
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
539 end
db045db @dhh Initial
dhh authored
540
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but was...
jamis authored
541 # Delivers a TMail::Mail object. By default, it delivers the cached mail
98dc582 @lifo Merge docrails.
lifo authored
542 # 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 was...
jamis authored
543 # no alternate has been given as the parameter, this will fail.
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
544 def deliver!(mail = @mail)
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but was...
jamis authored
545 raise "no mail object available for delivery!" unless mail
09f798b @josevalim Instrument create and deliver in ActionMailer.
josevalim authored
546
43d5504 @josevalim Move all render and layout pieces required in ActionMailer from ActionCo...
josevalim authored
547 if logger
be36455 @jeremy Ruby 1.9 compat: use Array() instead of #to_a.
jeremy authored
548 logger.info "Sent mail to #{Array(recipients).join(', ')}"
fbd3eb7 @jeremy Less verbose mail logging: just recipients for :info log level; the whol...
jeremy authored
549 logger.debug "\n#{mail.encoded}"
550 end
256e800 @dhh Fixed quoting for all address headers, not just to #955 [Jamis Buck] Add...
dhh authored
551
2d7abe2 @josevalim Renamed Orchestra to Notifications once again [#3321 state:resolved]
josevalim authored
552 ActiveSupport::Notifications.instrument(:deliver_mail, :mail => @mail) do
09f798b @josevalim Instrument create and deliver in ActionMailer.
josevalim authored
553 begin
f4f7677 @matthewrudy abstract all of the ActionMailer delivery methods into their own classes...
matthewrudy authored
554 self.delivery_method.perform_delivery(mail) if perform_deliveries
09f798b @josevalim Instrument create and deliver in ActionMailer.
josevalim authored
555 rescue Exception => e # Net::SMTP errors or sendmail pipe errors
556 raise e if raise_delivery_errors
557 end
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
558 end
3fad0cd @dhh Added support for charsets for both subject and body. The default charse...
dhh authored
559
09f798b @josevalim Instrument create and deliver in ActionMailer.
josevalim authored
560 mail
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
561 end
3fad0cd @dhh Added support for charsets for both subject and body. The default charse...
dhh authored
562
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
563 private
f474f33 @jamis Move mailer initialization to a separate (overridable) method, so that s...
jamis authored
564 # Set up the default values for the various instance variables of this
565 # mailer. Subclasses may override this method to provide different
566 # defaults.
567 def initialize_defaults(method_name)
95e8740 @dhh Allow Mailers to have custom initialize methods that set default instanc...
dhh authored
568 @charset ||= @@default_charset.dup
569 @content_type ||= @@default_content_type.dup
570 @implicit_parts_order ||= @@default_implicit_parts_order.dup
571 @template ||= method_name
6228220 @dhh Revert "Revert "Add layout functionality to mailers.""
dhh authored
572 @default_template_name = @action_name = @template
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
573 @mailer_name ||= self.class.name.underscore
95e8740 @dhh Allow Mailers to have custom initialize methods that set default instanc...
dhh authored
574 @parts ||= []
575 @headers ||= {}
576 @body ||= {}
dca4d4e @jamis Multipart messages specify a MIME-Version header automatically #2003 [Jo...
jamis authored
577 @mime_version = @@default_mime_version.dup if @@default_mime_version
5fdc33c @mrduncan Default sent_on time to now in ActionMailer
mrduncan authored
578 @sent_on ||= Time.now
f474f33 @jamis Move mailer initialization to a separate (overridable) method, so that s...
jamis authored
579 end
580
43d5504 @josevalim Move all render and layout pieces required in ActionMailer from ActionCo...
josevalim authored
581 def render(*args)
582 # TODO Fix me. Deprecate assigns to be given as a :body hash
583 options = args.last.is_a?(Hash) ? args.last : {}
584 if options[:body]
585 options.delete(:body).each do |k, v|
586 instance_variable_set(:"@#{k}", v)
587 end
a9751a7 @josevalim Refactor ActionMailer layout and remove legacy one.
josevalim authored
588 end
589
43d5504 @josevalim Move all render and layout pieces required in ActionMailer from ActionCo...
josevalim authored
590 super
6228220 @dhh Revert "Revert "Add layout functionality to mailers.""
dhh authored
591 end
592
cb21db1 @josh Treat ActionMailer template_root as a view path set internally to avoid ...
josh authored
593 def template_root
594 self.class.template_root
595 end
596
597 def template_root=(root)
598 self.class.template_root = root
599 end
600
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
601 def template_path
0a132c2 Refactor ActionView::Path
Yehuda Katz + Carl Lerche authored
602 "#{mailer_name}"
db045db @dhh Initial
dhh authored
603 end
604
5c98152 @jamis Better multipart support with implicit multipart/alternative and sorting...
jamis authored
605 def sort_parts(parts, order = [])
606 order = order.collect { |s| s.downcase }
8b340ab @josevalim Revert "Rename Orchestra to Notifications [#3321 state:resolved]"
josevalim authored
607
5c98152 @jamis Better multipart support with implicit multipart/alternative and sorting...
jamis authored
608 parts = parts.sort do |a, b|
609 a_ct = a.content_type.downcase
610 b_ct = b.content_type.downcase
611
612 a_in = order.include? a_ct
613 b_in = order.include? b_ct
614
615 s = case
616 when a_in && b_in
617 order.index(a_ct) <=> order.index(b_ct)
618 when a_in
619 -1
620 when b_in
621 1
622 else
623 a_ct <=> b_ct
624 end
625
626 # reverse the ordering because parts that come last are displayed
627 # first in mail clients
628 (s * -1)
629 end
630
631 parts
632 end
633
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
634 def create_mail
635 m = TMail::Mail.new
74a612c @dhh Added that delivery errors are caught in a way so the mail is still retu...
dhh authored
636
cf6299d Add ActionMailer#reply_to. [#245 state:resolved]
Adam authored
637 m.subject, = quote_any_if_necessary(charset, subject)
638 m.to, m.from = quote_any_address_if_necessary(charset, recipients, from)
639 m.bcc = quote_address_if_necessary(bcc, charset) unless bcc.nil?
640 m.cc = quote_address_if_necessary(cc, charset) unless cc.nil?
641 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 [Jo...
jamis authored
642 m.mime_version = mime_version unless mime_version.nil?
cf6299d Add ActionMailer#reply_to. [#245 state:resolved]
Adam authored
643 m.date = sent_on.to_time rescue sent_on if sent_on
644
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
645 headers.each { |k, v| m[k] = v }
db045db @dhh Initial
dhh authored
646
db0e8ff @jamis Parse content-type apart before using it so that sub-parts of the header...
jamis authored
647 real_content_type, ctype_attrs = parse_content_type
8b340ab @josevalim Revert "Rename Orchestra to Notifications [#3321 state:resolved]"
josevalim authored
648
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
649 if @parts.empty?
db0e8ff @jamis Parse content-type apart before using it so that sub-parts of the header...
jamis authored
650 m.set_content_type(real_content_type, nil, ctype_attrs)
e201fc7 @josh use autoload instead of explicit requires for ActionMailer
josh authored
651 m.body = normalize_new_lines(body)
0a132c2 Refactor ActionView::Path
Yehuda Katz + Carl Lerche authored
652 elsif @parts.size == 1 && @parts.first.parts.empty?
653 m.set_content_type(real_content_type, nil, ctype_attrs)
654 m.body = normalize_new_lines(@parts.first.body)
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
655 else
656 if String === body
657 part = TMail::Mail.new
e201fc7 @josh use autoload instead of explicit requires for ActionMailer
josh authored
658 part.body = normalize_new_lines(body)
db0e8ff @jamis Parse content-type apart before using it so that sub-parts of the header...
jamis authored
659 part.set_content_type(real_content_type, nil, ctype_attrs)
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
660 part.set_content_disposition "inline"
661 m.parts << part
662 end
3fad0cd @dhh Added support for charsets for both subject and body. The default charse...
dhh authored
663
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
664 @parts.each do |p|
665 part = (TMail::Mail === p ? p : p.to_mail(self))
666 m.parts << part
667 end
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
668
49efa02 @jamis Nil charset caused subject line to be improperly quoted in implicitly mu...
jamis authored
669 if real_content_type =~ /multipart/
670 ctype_attrs.delete "charset"
671 m.set_content_type(real_content_type, nil, ctype_attrs)
672 end
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
673 end
256e800 @dhh Fixed quoting for all address headers, not just to #955 [Jamis Buck] Add...
dhh authored
674
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
675 @mail = m
256e800 @dhh Fixed quoting for all address headers, not just to #955 [Jamis Buck] Add...
dhh authored
676 end
677
db045db @dhh Initial
dhh authored
678 end
679 end
Something went wrong with that request. Please try again.