Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 500 lines (445 sloc) 21.284 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 Tmail...
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, Mar...
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 Inflect...
josh authored
11 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
12 # $ script/generate mailer Notifier
13 #
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
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, Mar...
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, Mar...
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, Mar...
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, Mar...
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, Mar...
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 Inflect...
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, Mar...
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 ma...
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 Inflect...
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 Inflect...
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 Inflect...
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 Inflect...
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 Inflect...
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 Inflect...
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 Inflect...
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 Inflect...
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 Inflect...
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, Mar...
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 Inflect...
josh authored
112 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
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, Mar...
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 and ...
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 and ...
jamis authored
132 # end
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
133 # end
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
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, Mar...
Marcel Molina authored
138 # You can explicitly specify multipart messages:
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
139 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
140 # class ApplicationMailer < ActionMailer::Base
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
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 and ...
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 and ...
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 Tmail...
mikel authored
153 # p.content_transfer_encoding = "base64"
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
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+.
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 ma...
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 use ...
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 Abstract...
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 ActionMai...
josevalim authored
262 include AbstractController::UrlFor
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
263
ee70d1b @josevalim adv_attr_accessors in ActionMailer are not sent to the views, use the ma...
josevalim authored
264 helper ActionMailer::MailHelper
418c3f8 @josevalim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
265 include ActionMailer::DeprecatedBody
10c509f @mikel Moved old API into deprecated_api.rb in preparation for new Rails 3 Mail...
mikel authored
266 include ActionMailer::DeprecatedApi
418c3f8 @josevalim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
267
e10f51b @josevalim Refactor delivery methods.
josevalim authored
268 include ActionMailer::DeliveryMethods
269
10c509f @mikel Moved old API into deprecated_api.rb in preparation for new Rails 3 Mail...
mikel authored
270
c927aa0 @dhh Updated documentation
dhh authored
271 private_class_method :new #:nodoc:
db045db @dhh Initial
dhh authored
272
273 @@raise_delivery_errors = true
274 cattr_accessor :raise_delivery_errors
275
276 @@perform_deliveries = true
277 cattr_accessor :perform_deliveries
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
278
db045db @dhh Initial
dhh authored
279 @@deliveries = []
280 cattr_accessor :deliveries
281
3fad0cd @dhh Added support for charsets for both subject and body. The default charse...
dhh authored
282 @@default_charset = "utf-8"
283 cattr_accessor :default_charset
284
100fd72 @jamis Added a "content_type" accessor to allow messages to explicitly specify ...
jamis authored
285 @@default_content_type = "text/plain"
286 cattr_accessor :default_content_type
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
287
45b5555 @jamis Make mime version default to 1.0. closes #2323
jamis authored
288 @@default_mime_version = "1.0"
dca4d4e @jamis Multipart messages specify a MIME-Version header automatically #2003 [Jo...
jamis authored
289 cattr_accessor :default_mime_version
100fd72 @jamis Added a "content_type" accessor to allow messages to explicitly specify ...
jamis authored
290
c039bcd @mikel Moved sort_parts into Mail, updated mail requirement to 1.4.2
mikel authored
291 # This specifies the order that the parts of a multipart email will be. Usually you put
292 # text/plain at the top so someone without a MIME capable email reader can read the plain
293 # text of your email first.
294 #
295 # Any content type that is not listed here will be inserted in the order you add them to
296 # the email after the content types you list here.
297 @@default_implicit_parts_order = [ "text/plain", "text/enriched", "text/html" ]
5c98152 @jamis Better multipart support with implicit multipart/alternative and sorting...
jamis authored
298 cattr_accessor :default_implicit_parts_order
299
ee70d1b @josevalim adv_attr_accessors in ActionMailer are not sent to the views, use the ma...
josevalim authored
300 @@protected_instance_variables = %w(@parts @mail)
81c416b @josevalim More refactoring on ActionMailer::Base.
josevalim authored
301 cattr_reader :protected_instance_variables
28bf2fa @josh Protect body ivar from being clobbered by the mailer template assigns
josh authored
302
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
303 # Specify the BCC addresses for the message
304 adv_attr_accessor :bcc
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
305
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
306 # Specify the CC addresses for the message.
307 adv_attr_accessor :cc
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
308
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
309 # Specify the charset to use for the message. This defaults to the
310 # +default_charset+ specified for ActionMailer::Base.
311 adv_attr_accessor :charset
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
312
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
313 # Specify the content type for the message. This defaults to <tt>text/plain</tt>
314 # in most cases, but can be automatically set in some situations.
315 adv_attr_accessor :content_type
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 from address for the message.
318 adv_attr_accessor :from
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
319
cf6299d Add ActionMailer#reply_to. [#245 state:resolved]
Adam authored
320 # Specify the address (if different than the "from" address) to direct
321 # replies to this message.
322 adv_attr_accessor :reply_to
323
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
324 # Specify additional headers to be added to the message.
325 adv_attr_accessor :headers
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
326
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
327 # Specify the order in which parts should be sorted, based on content-type.
328 # This defaults to the value for the +default_implicit_parts_order+.
329 adv_attr_accessor :implicit_parts_order
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
330
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
331 # Defaults to "1.0", but may be explicitly given if needed.
332 adv_attr_accessor :mime_version
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
333
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
334 # The recipient addresses for the message, either as a string (for a single
335 # address) or an array (for multiple addresses).
336 adv_attr_accessor :recipients
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 # The date on which the message was sent. If not set (the default), the
339 # header will be set by the delivery agent.
340 adv_attr_accessor :sent_on
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 # Specify the subject of the message.
343 adv_attr_accessor :subject
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 # Specify the template name to use for current message. This is the "base"
346 # template name, without the extension or directory, and may be used to
347 # have multiple mailer methods share the same template.
348 adv_attr_accessor :template
165097e @dhh Added access to custom headers, like cc, bcc, and reply-to #268 [Andreas...
dhh authored
349
bd5ed65 @technoweenie Update ActionMailer so it treats ActionView the same way that ActionCont...
technoweenie authored
350 # Override the mailer name, which defaults to an inflected version of the
351 # mailer's class name. If you want to use a template in a non-standard
352 # location, you can use this to specify that location.
4964d3b @josevalim Make ActionMailer::Base inherit from AbstractController::Base
josevalim authored
353 adv_attr_accessor :mailer_name
418c3f8 @josevalim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
354
4964d3b @josevalim Make ActionMailer::Base inherit from AbstractController::Base
josevalim authored
355 # Expose the internal mail
356 attr_reader :mail
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
357
418c3f8 @josevalim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
358 # Alias controller_path to mailer_name so render :partial in views work.
359 alias :controller_path :mailer_name
43d5504 @josevalim Move all render and layout pieces required in ActionMailer from ActionCo...
josevalim authored
360
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but was...
jamis authored
361 class << self
81c416b @josevalim More refactoring on ActionMailer::Base.
josevalim authored
362
bd5ed65 @technoweenie Update ActionMailer so it treats ActionView the same way that ActionCont...
technoweenie authored
363 def mailer_name
364 @mailer_name ||= name.underscore
365 end
0750304 @mikel Migrated over to Mail doing delivery.
mikel authored
366 attr_writer :mailer_name
367
368 alias :controller_path :mailer_name
81c416b @josevalim More refactoring on ActionMailer::Base.
josevalim authored
369
3cf773b @floehopper ActionMailer should respond_to? to methods handled by method_missing [#7...
floehopper authored
370 def respond_to?(method_symbol, include_private = false) #:nodoc:
e10f51b @josevalim Refactor delivery methods.
josevalim authored
371 matches_dynamic_method?(method_symbol) || super
3cf773b @floehopper ActionMailer should respond_to? to methods handled by method_missing [#7...
floehopper authored
372 end
373
374 def method_missing(method_symbol, *parameters) #:nodoc:
a62e9e9 @mocoso Fix for ActionMailer::Base.method_missing so that it raises NoMethodErro...
mocoso authored
375 if match = matches_dynamic_method?(method_symbol)
376 case match[1]
377 when 'create' then new(match[2], *parameters).mail
378 when 'deliver' then new(match[2], *parameters).deliver!
379 when 'new' then nil
c65075f @mocoso Fixed method_missing for ActionMailer so it no longer matches methods wh...
mocoso authored
380 else super
a62e9e9 @mocoso Fix for ActionMailer::Base.method_missing so that it raises NoMethodErro...
mocoso authored
381 end
382 else
383 super
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but was...
jamis authored
384 end
385 end
386
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
387 # Receives a raw email, parses it into an email object, decodes it,
388 # instantiates a new mailer, and passes the email object to the mailer
98dc582 @lifo Merge docrails.
lifo authored
389 # object's +receive+ method. If you want your mailer to be able to
390 # process incoming messages, you'll need to implement a +receive+
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
391 # method that accepts the email object as a parameter:
392 #
393 # class MyMailer < ActionMailer::Base
394 # def receive(mail)
395 # ...
396 # end
397 # end
704daad @josevalim Ensure we just send Ruby Stdlib objects in ActionMailer notifications.
josevalim authored
398 def receive(raw_mail)
399 ActiveSupport::Notifications.instrument("action_mailer.receive") do |payload|
400 mail = Mail.new(raw_mail)
401 set_payload_for_mail(payload, mail)
2a6bc12 @josevalim Add subscriber to ActionMailer.
josevalim authored
402 new.receive(mail)
403 end
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but was...
jamis authored
404 end
405
406 # Deliver the given mail object directly. This can be used to deliver
407 # a preconstructed mail object, like:
408 #
409 # email = MyMailer.create_some_mail(parameters)
410 # email.set_some_obscure_header "frobnicate"
411 # MyMailer.deliver(email)
412 def deliver(mail)
0750304 @mikel Migrated over to Mail doing delivery.
mikel authored
413 raise "no mail object available for delivery!" unless mail
414
8b37fee @mikel Merge branch 'master' of git://github.com/rails/rails
mikel authored
415 ActiveSupport::Notifications.instrument("action_mailer.deliver", :mailer => self.name) do |payload|
e10f51b @josevalim Refactor delivery methods.
josevalim authored
416
8b37fee @mikel Merge branch 'master' of git://github.com/rails/rails
mikel authored
417 self.set_payload_for_mail(payload, mail)
418
419 mail.delivery_method delivery_methods[delivery_method],
420 delivery_settings[delivery_method]
e10f51b @josevalim Refactor delivery methods.
josevalim authored
421
8b37fee @mikel Merge branch 'master' of git://github.com/rails/rails
mikel authored
422 begin
423 # TODO Move me to the instance
0750304 @mikel Migrated over to Mail doing delivery.
mikel authored
424 if @@perform_deliveries
425 mail.deliver!
426 self.deliveries << mail
427 end
8b37fee @mikel Merge branch 'master' of git://github.com/rails/rails
mikel authored
428 rescue Exception => e # Net::SMTP errors or sendmail pipe errors
429 raise e if raise_delivery_errors
0750304 @mikel Migrated over to Mail doing delivery.
mikel authored
430 end
431 end
432
433 mail
434 end
435
cb21db1 @josh Treat ActionMailer template_root as a view path set internally to avoid ...
josh authored
436 def template_root
437 self.view_paths && self.view_paths.first
438 end
439
684c2dc @josevalim Remove ActionMailer helpers and rely on AbstractController one.
josevalim authored
440 # Should template root overwrite the whole view_paths?
61c90a4 @NZKoz Reapply the TemplateFinder first applied in [8669] then reverted in [867...
NZKoz authored
441 def template_root=(root)
cb21db1 @josh Treat ActionMailer template_root as a view path set internally to avoid ...
josh authored
442 self.view_paths = ActionView::Base.process_view_paths(root)
61c90a4 @NZKoz Reapply the TemplateFinder first applied in [8669] then reverted in [867...
NZKoz authored
443 end
3cf773b @floehopper ActionMailer should respond_to? to methods handled by method_missing [#7...
floehopper authored
444
704daad @josevalim Ensure we just send Ruby Stdlib objects in ActionMailer notifications.
josevalim authored
445 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 not ...
josevalim authored
446 payload[:message_id] = mail.message_id
447 payload[:subject] = mail.subject
448 payload[:to] = mail.to
449 payload[:from] = mail.from
450 payload[:bcc] = mail.bcc if mail.bcc.present?
451 payload[:cc] = mail.cc if mail.cc.present?
452 payload[:date] = mail.date
453 payload[:mail] = mail.encoded
704daad @josevalim Ensure we just send Ruby Stdlib objects in ActionMailer notifications.
josevalim authored
454 end
455
3cf773b @floehopper ActionMailer should respond_to? to methods handled by method_missing [#7...
floehopper authored
456 private
c8e2998 @mikel First pass on fixing delivery method
mikel authored
457
3cf773b @floehopper ActionMailer should respond_to? to methods handled by method_missing [#7...
floehopper authored
458 def matches_dynamic_method?(method_name) #:nodoc:
459 method_name = method_name.to_s
c65075f @mocoso Fixed method_missing for ActionMailer so it no longer matches methods wh...
mocoso authored
460 /^(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
461 end
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but was...
jamis authored
462 end
463
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
464 # Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer
465 # will be initialized according to the named method. If not, the mailer will
466 # remain uninitialized (useful when you only need to invoke the "receive"
467 # method, for instance).
971f4ff @josevalim DRY ActionMailer code.
josevalim authored
468 def initialize(method_name=nil, *args)
d887e46 @jeremy Be sure to invoke the super chain! And initialize response body.
jeremy authored
469 super()
10c509f @mikel Moved old API into deprecated_api.rb in preparation for new Rails 3 Mail...
mikel authored
470 @mail = Mail.new
4964d3b @josevalim Make ActionMailer::Base inherit from AbstractController::Base
josevalim authored
471 process(method_name, *args) if method_name
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
472 end
473
4964d3b @josevalim Make ActionMailer::Base inherit from AbstractController::Base
josevalim authored
474 # Process the mailer via the given +method_name+. The body will be
971f4ff @josevalim DRY ActionMailer code.
josevalim authored
475 # rendered and a new Mail object created.
476 def process(method_name, *args)
43d5504 @josevalim Move all render and layout pieces required in ActionMailer from ActionCo...
josevalim authored
477 initialize_defaults(method_name)
4964d3b @josevalim Make ActionMailer::Base inherit from AbstractController::Base
josevalim authored
478 super
43d5504 @josevalim Move all render and layout pieces required in ActionMailer from ActionCo...
josevalim authored
479
418c3f8 @josevalim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
480 # Create e-mail parts
481 create_parts
09f798b @josevalim Instrument create and deliver in ActionMailer.
josevalim authored
482
2aafdc8 @josevalim Use I18n on ActionMailer subjects by default.
josevalim authored
483 # Set the subject if not set yet
4a1f438 @josevalim Change mailer subjects lookup.
josevalim authored
484 @subject ||= I18n.t(:subject, :scope => [:actionmailer, mailer_name, method_name],
485 :default => method_name.humanize)
43d5504 @josevalim Move all render and layout pieces required in ActionMailer from ActionCo...
josevalim authored
486
4964d3b @josevalim Make ActionMailer::Base inherit from AbstractController::Base
josevalim authored
487 # Build the mail object itself
88ba056 @josevalim Refactor multiple parts logic and move Utils to PartContainer.
josevalim authored
488 create_mail
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
489 end
db045db @dhh Initial
dhh authored
490
15d7cac @mikel Starting again on actionmailer integration with mail
mikel authored
491 # Delivers a Mail object. By default, it delivers the cached mail
98dc582 @lifo Merge docrails.
lifo authored
492 # 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
493 # no alternate has been given as the parameter, this will fail.
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
494 def deliver!(mail = @mail)
0750304 @mikel Migrated over to Mail doing delivery.
mikel authored
495 self.class.deliver(mail)
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
496 end
3fad0cd @dhh Added support for charsets for both subject and body. The default charse...
dhh authored
497
db045db @dhh Initial
dhh authored
498 end
499 end
Something went wrong with that request. Please try again.