Skip to content
This repository
Newer
Older
100644 472 lines (430 sloc) 20.781 kb
a9751a70 » josevalim
2009-10-17 Refactor ActionMailer layout and remove legacy one.
1 require 'active_support/core_ext/class'
d3da87ce » mikel
2010-01-21 Mail method accepting all headers set via the hash
2 require "active_support/core_ext/module/delegation"
616ebb8f » josevalim
2009-12-28 Remove unused code paths and require mail only when it's needed.
3 require 'mail'
a2880827 » mikel
2009-12-30 Adding :transfer_encoding -> :content_transfer_encoding as part of Tm…
4 require 'action_mailer/tmail_compat'
a63caa4c » Yehuda Katz + Carl Lerche
2009-06-15 Get tests to run (with failures) without old base around
5
c4590d57 » dhh
2006-03-28 Fixed docs
6 module ActionMailer #:nodoc:
98dc5827 » lifo
2008-05-25 Merge docrails.
7 # Action Mailer allows you to send email from your application using a mailer model and views.
db045dbb » dhh
2004-11-24 Initial
8 #
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
9 # = Mailer Models
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
10 #
98dc5827 » lifo
2008-05-25 Merge docrails.
11 # To use Action Mailer, you need to create a mailer model.
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
12 #
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
13 # $ script/generate mailer Notifier
14 #
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
15 # The generated model inherits from ActionMailer::Base. Emails are defined by creating methods within the model which are then
16 # used to set variables to be used in the mail template, to change options on the mail, or
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
17 # to add attachments.
18 #
19 # Examples:
20 #
21 # class Notifier < ActionMailer::Base
22 # def signup_notification(recipient)
23 # recipients recipient.email_address_with_name
c3f53f41 » lifo
2008-12-19 Merge docrails
24 # bcc ["bcc@example.com", "Order Watcher <watcher@example.com>"]
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
25 # from "system@example.com"
26 # subject "New account information"
a0374582 » josevalim
2010-01-19 Bring body(Hash) behavior back.
27 # body :account => recipient
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
28 # end
29 # end
30 #
31 # Mailer methods have the following configuration methods available.
32 #
33 # * <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.
34 # * <tt>subject</tt> - The subject of your email. Sets the <tt>Subject:</tt> header.
35 # * <tt>from</tt> - Who the email you are sending is from. Sets the <tt>From:</tt> header.
36 # * <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.
cf6299db » Adam
2008-05-23 Add ActionMailer#reply_to. [#245 state:resolved]
37 # * <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.
38 # * <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.
dba196cb » lifo
2010-01-17 Merge docrails
39 # * <tt>sent_on</tt> - The date on which the message was sent. If not set, the header will be set by the delivery agent.
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
40 # * <tt>content_type</tt> - Specify the content type of the message. Defaults to <tt>text/plain</tt>.
41 # * <tt>headers</tt> - Specify additional headers to be set for the message, e.g. <tt>headers 'X-Mail-Count' => 107370</tt>.
42 #
5c0d38f6 » dhh
2008-03-27 Fixed that a return-path header would be ignored (closes #7572) [joost]
43 # When a <tt>headers 'return-path'</tt> is specified, that value will be used as the 'envelope from'
44 # address. Setting this is useful when you want delivery notifications sent to a different address than
45 # the one in <tt>from</tt>.
46 #
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
47 #
48 # = Mailer views
49 #
98dc5827 » lifo
2008-05-25 Merge docrails.
50 # Like Action Controller, each mailer class has a corresponding view directory
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
51 # in which each method of the class looks for a template with its name.
21187c0f » dhh
2007-02-21 Apply the rest of Chads patch
52 # To define a template to be used with a mailing, create an <tt>.erb</tt> file with the same name as the method
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
53 # in your mailer model. For example, in the mailer defined above, the template at
21187c0f » dhh
2007-02-21 Apply the rest of Chads patch
54 # <tt>app/views/notifier/signup_notification.erb</tt> would be used to generate the email.
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
55 #
56 # Variables defined in the model are accessible as instance variables in the view.
57 #
58 # Emails by default are sent in plain text, so a sample view for our model example might look like this:
59 #
60 # Hi <%= @account.name %>,
61 # Thanks for joining our service! Please check back often.
62 #
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
63 # You can even use Action Pack helpers in these views. For example:
64 #
65 # You got a new note!
ee70d1b6 » josevalim
2009-12-25 adv_attr_accessors in ActionMailer are not sent to the views, use the…
66 # <%= truncate(@note.body, 25) %>
67 #
68 # If you need to access the subject, from or the recipients in the view, you can do that through mailer object:
69 #
70 # You got a new note from <%= mailer.from %>!
71 # <%= truncate(@note.body, 25) %>
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
72 #
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
73 #
4809dcc1 » Cody Fauser
2008-04-21 * Remove default_url_options from mailer generator
74 # = Generating URLs
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
75 #
4809dcc1 » Cody Fauser
2008-04-21 * Remove default_url_options from mailer generator
76 # URLs can be generated in mailer views using <tt>url_for</tt> or named routes.
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
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.
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
79 #
4809dcc1 » Cody Fauser
2008-04-21 * Remove default_url_options from mailer generator
80 # When using <tt>url_for</tt> you'll need to provide the <tt>:host</tt>, <tt>:controller</tt>, and <tt>:action</tt>:
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
81 #
4809dcc1 » Cody Fauser
2008-04-21 * Remove default_url_options from mailer generator
82 # <%= url_for(:host => "example.com", :controller => "welcome", :action => "greeting") %>
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
83 #
4809dcc1 » Cody Fauser
2008-04-21 * Remove default_url_options from mailer generator
84 # When using named routes you only need to supply the <tt>:host</tt>:
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
85 #
4809dcc1 » Cody Fauser
2008-04-21 * Remove default_url_options from mailer generator
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 #
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
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
4809dcc1 » Cody Fauser
2008-04-21 * Remove default_url_options from mailer generator
92 # the <tt>ActionMailer::Base.default_url_options</tt> hash as follows:
93 #
94 # ActionMailer::Base.default_url_options[:host] = "example.com"
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
95 #
dc4eec11 » lifo
2008-05-09 Merge docrails:
96 # This can also be set as a configuration option in <tt>config/environment.rb</tt>:
4809dcc1 » Cody Fauser
2008-04-21 * Remove default_url_options from mailer generator
97 #
98 # config.action_mailer.default_url_options = { :host => "example.com" }
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
99 #
4809dcc1 » Cody Fauser
2008-04-21 * Remove default_url_options from mailer generator
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
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
102 # the <tt>url_for</tt> view helper will, by default, generate relative URLs when a <tt>:host</tt> option isn't
4809dcc1 » Cody Fauser
2008-04-21 * Remove default_url_options from mailer generator
103 # explicitly provided.
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
104 #
105 # = Sending mail
106 #
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
107 # Once a mailer action and template are defined, you can deliver your message or create it and save it
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
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)
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
113 #
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
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 #
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
120 #
121 # = HTML email
122 #
21187c0f » dhh
2007-02-21 Apply the rest of Chads patch
123 # To send mail as HTML, make sure your view (the <tt>.erb</tt> file) generates HTML and
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
124 # set the content type to html.
125 #
126 # class MyMailer < ActionMailer::Base
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
127 # def signup_notification(recipient)
46f30f90 » lifo
2008-05-16 Merge documentation changes from docrails.
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"
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
133 # end
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
134 # end
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
135 #
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
136 #
137 # = Multipart email
138 #
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
139 # You can explicitly specify multipart messages:
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
140 #
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
141 # class ApplicationMailer < ActionMailer::Base
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
142 # def signup_notification(recipient)
143 # recipients recipient.email_address_with_name
144 # subject "New account information"
145 # from "system@example.com"
46f30f90 » lifo
2008-05-16 Merge documentation changes from docrails.
146 # content_type "multipart/alternative"
f00cbf78 » josevalim
2010-01-19 Bring render_message back for 2.3 compatibility.
147 # body :account => recipient
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
148 #
149 # part :content_type => "text/html",
f00cbf78 » josevalim
2010-01-19 Bring render_message back for 2.3 compatibility.
150 # :data => render_message("signup-as-html")
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
151 #
152 # part "text/plain" do |p|
f00cbf78 » josevalim
2010-01-19 Bring render_message back for 2.3 compatibility.
153 # p.body = render_message("signup-as-plain")
a2880827 » mikel
2009-12-30 Adding :transfer_encoding -> :content_transfer_encoding as part of Tm…
154 # p.content_transfer_encoding = "base64"
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
155 # end
156 # end
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
157 # end
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
158 #
98dc5827 » lifo
2008-05-25 Merge docrails.
159 # Multipart messages can also be used implicitly because Action Mailer will automatically
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
160 # detect and use multipart templates, where each template is named after the name of the action, followed
161 # by the content type. Each such detected template will be added as separate part to the message.
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
162 #
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
163 # For example, if the following templates existed:
21187c0f » dhh
2007-02-21 Apply the rest of Chads patch
164 # * signup_notification.text.plain.erb
165 # * signup_notification.text.html.erb
166 # * signup_notification.text.xml.builder
167 # * signup_notification.text.x-yaml.erb
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
168 #
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
169 # Each would be rendered and added as a separate part to the message,
46f30f90 » lifo
2008-05-16 Merge documentation changes from docrails.
170 # with the corresponding content type. The content type for the entire
171 # message is automatically set to <tt>multipart/alternative</tt>, which indicates
172 # that the email contains multiple different representations of the same email
173 # body. The same body hash is passed to each template.
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
174 #
46f30f90 » lifo
2008-05-16 Merge documentation changes from docrails.
175 # Implicit template rendering is not performed if any attachments or parts have been added to the email.
176 # This means that you'll have to manually add each part to the email and set the content type of the email
177 # to <tt>multipart/alternative</tt>.
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
178 #
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
179 # = Attachments
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
180 #
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
181 # Attachments can be added by using the +attachment+ method.
182 #
183 # Example:
184 #
185 # class ApplicationMailer < ActionMailer::Base
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
186 # # attachments
187 # def signup_notification(recipient)
188 # recipients recipient.email_address_with_name
189 # subject "New account information"
190 # from "system@example.com"
191 #
192 # attachment :content_type => "image/jpeg",
193 # :body => File.read("an-image.jpg")
194 #
195 # attachment "application/pdf" do |a|
196 # a.body = generate_your_pdf_here()
197 # end
db045dbb » dhh
2004-11-24 Initial
198 # end
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
199 # end
c927aa0f » dhh
2004-12-16 Updated documentation
200 #
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
201 #
c927aa0f » dhh
2004-12-16 Updated documentation
202 # = Configuration options
203 #
204 # These options are specified on the class level, like <tt>ActionMailer::Base.template_root = "/my/templates"</tt>
205 #
64092de2 » fxn
2008-05-02 Improve documentation coverage and markup
206 # * <tt>template_root</tt> - Determines the base from which template references will be made.
c927aa0f » dhh
2004-12-16 Updated documentation
207 #
208 # * <tt>logger</tt> - the logger is used for generating information on the mailing run if available.
209 # Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers.
210 #
64092de2 » fxn
2008-05-02 Improve documentation coverage and markup
211 # * <tt>smtp_settings</tt> - Allows detailed configuration for <tt>:smtp</tt> delivery method:
dc4eec11 » lifo
2008-05-09 Merge docrails:
212 # * <tt>:address</tt> - Allows you to use a remote mail server. Just change it from its default "localhost" setting.
213 # * <tt>:port</tt> - On the off chance that your mail server doesn't run on port 25, you can change it.
214 # * <tt>:domain</tt> - If you need to specify a HELO domain, you can do it here.
215 # * <tt>:user_name</tt> - If your mail server requires authentication, set the username in this setting.
216 # * <tt>:password</tt> - If your mail server requires authentication, set the password in this setting.
b2504f8b » josh
2008-08-06 Tidy up ActionMailer rendering logic to take advantage of view path c…
217 # * <tt>:authentication</tt> - If your mail server requires authentication, you need to specify the authentication type here.
46f30f90 » lifo
2008-05-16 Merge documentation changes from docrails.
218 # This is a symbol and one of <tt>:plain</tt>, <tt>:login</tt>, <tt>:cram_md5</tt>.
c2e7851f » josevalim
2009-01-11 Add ActionMailer::Base#enable_starttls_auto option for enabling/disab…
219 # * <tt>:enable_starttls_auto</tt> - When set to true, detects if STARTTLS is enabled in your SMTP server and starts to use it.
220 # It works only on Ruby >= 1.8.7 and Ruby >= 1.9. Default is true.
c927aa0f » dhh
2004-12-16 Updated documentation
221 #
46f30f90 » lifo
2008-05-16 Merge documentation changes from docrails.
222 # * <tt>sendmail_settings</tt> - Allows you to override options for the <tt>:sendmail</tt> delivery method.
223 # * <tt>:location</tt> - The location of the sendmail executable. Defaults to <tt>/usr/sbin/sendmail</tt>.
224 # * <tt>:arguments</tt> - The command line arguments. Defaults to <tt>-i -t</tt>.
dc4eec11 » lifo
2008-05-09 Merge docrails:
225 #
fbe6c3c1 » edavis10
2009-08-07 Adds a :file delivery_method to save email to a file on disk
226 # * <tt>file_settings</tt> - Allows you to override options for the <tt>:file</tt> delivery method.
227 # * <tt>:location</tt> - The directory into which emails will be written. Defaults to the application <tt>tmp/mails</tt>.
228 #
dc4eec11 » lifo
2008-05-09 Merge docrails:
229 # * <tt>raise_delivery_errors</tt> - Whether or not errors should be raised if the email fails to be delivered.
c927aa0f » dhh
2004-12-16 Updated documentation
230 #
fbe6c3c1 » edavis10
2009-08-07 Adds a :file delivery_method to save email to a file on disk
231 # * <tt>delivery_method</tt> - Defines a delivery method. Possible values are <tt>:smtp</tt> (default), <tt>:sendmail</tt>, <tt>:test</tt>,
f4f76772 » matthewrudy
2009-10-28 abstract all of the ActionMailer delivery methods into their own clas…
232 # and <tt>:file</tt>. Or you may provide a custom delivery method object eg. MyOwnDeliveryMethodClass.new
c927aa0f » dhh
2004-12-16 Updated documentation
233 #
dc4eec11 » lifo
2008-05-09 Merge docrails:
234 # * <tt>perform_deliveries</tt> - Determines whether <tt>deliver_*</tt> methods are actually carried out. By default they are,
c927aa0f » dhh
2004-12-16 Updated documentation
235 # but this can be turned off to help functional testing.
236 #
64092de2 » fxn
2008-05-02 Improve documentation coverage and markup
237 # * <tt>deliveries</tt> - Keeps an array of all the emails sent out through the Action Mailer with <tt>delivery_method :test</tt>. Most useful
c927aa0f » dhh
2004-12-16 Updated documentation
238 # for unit and functional testing.
af56c806 » dhh
2005-02-24 Updated documentation
239 #
b2504f8b » josh
2008-08-06 Tidy up ActionMailer rendering logic to take advantage of view path c…
240 # * <tt>default_charset</tt> - The default charset used for the body and to encode the subject. Defaults to UTF-8. You can also
46f30f90 » lifo
2008-05-16 Merge documentation changes from docrails.
241 # pick a different charset from inside a method with +charset+.
c2e7851f » josevalim
2009-01-11 Add ActionMailer::Base#enable_starttls_auto option for enabling/disab…
242 #
475bd741 » dhh
2005-10-26 Fix docs (closes #2598)
243 # * <tt>default_content_type</tt> - The default content type used for the main part of the message. Defaults to "text/plain". You
b2504f8b » josh
2008-08-06 Tidy up ActionMailer rendering logic to take advantage of view path c…
244 # can also pick a different content type from inside a method with +content_type+.
c2e7851f » josevalim
2009-01-11 Add ActionMailer::Base#enable_starttls_auto option for enabling/disab…
245 #
46f30f90 » lifo
2008-05-16 Merge documentation changes from docrails.
246 # * <tt>default_mime_version</tt> - The default mime version used for the message. Defaults to <tt>1.0</tt>. You
247 # can also pick a different value from inside a method with +mime_version+.
c2e7851f » josevalim
2009-01-11 Add ActionMailer::Base#enable_starttls_auto option for enabling/disab…
248 #
475bd741 » dhh
2005-10-26 Fix docs (closes #2598)
249 # * <tt>default_implicit_parts_order</tt> - When a message is built implicitly (i.e. multiple parts are assembled from templates
5c981528 » jamis
2005-07-01 Better multipart support with implicit multipart/alternative and sort…
250 # which specify the content type in their filenames) this variable controls how the parts are ordered. Defaults to
46f30f90 » lifo
2008-05-16 Merge documentation changes from docrails.
251 # <tt>["text/html", "text/enriched", "text/plain"]</tt>. Items that appear first in the array have higher priority in the mail client
5c981528 » jamis
2005-07-01 Better multipart support with implicit multipart/alternative and sort…
252 # and appear last in the mime encoded message. You can also pick a different order from inside a method with
46f30f90 » lifo
2008-05-16 Merge documentation changes from docrails.
253 # +implicit_parts_order+.
4964d3b0 » josevalim
2009-12-22 Make ActionMailer::Base inherit from AbstractController::Base
254 class Base < AbstractController::Base
47e5caa9 » josevalim
2009-12-27 Merge Mail with latest Rails and move mail gem to Gemfile.
255 include Quoting
a9751a70 » josevalim
2009-10-17 Refactor ActionMailer layout and remove legacy one.
256
c03c40b4 » josevalim
2009-12-31 Expose a _render_partial hook as thhe _render_template one and make u…
257 include AbstractController::Logger
83f4d86a » dhh
2009-12-20 Rename the RenderingController module to just plain Rendering
258 include AbstractController::Rendering
976c2647 » josevalim
2009-10-28 Extracted localized_cache.rb from ActionController, added it to Abstr…
259 include AbstractController::LocalizedCache
a9751a70 » josevalim
2009-10-17 Refactor ActionMailer layout and remove legacy one.
260 include AbstractController::Layouts
684c2dc2 » josevalim
2009-10-18 Remove ActionMailer helpers and rely on AbstractController one.
261 include AbstractController::Helpers
f564f947 » josevalim
2010-01-07 Remove duplicated url_for code and move methods shared between Action…
262 include AbstractController::UrlFor
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
263
ee70d1b6 » josevalim
2009-12-25 adv_attr_accessors in ActionMailer are not sent to the views, use the…
264 helper ActionMailer::MailHelper
10c509fb » mikel
2010-01-20 Moved old API into deprecated_api.rb in preparation for new Rails 3 M…
265 include ActionMailer::DeprecatedApi
418c3f80 » josevalim
2009-10-21 Another refactoring on AM. body is deprecated, use render instead.
266
e10f51b6 » josevalim
2010-01-19 Refactor delivery methods.
267 include ActionMailer::DeliveryMethods
268
c927aa0f » dhh
2004-12-16 Updated documentation
269 private_class_method :new #:nodoc:
db045dbb » dhh
2004-11-24 Initial
270
271 @@raise_delivery_errors = true
272 cattr_accessor :raise_delivery_errors
273
274 @@perform_deliveries = true
275 cattr_accessor :perform_deliveries
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
276
db045dbb » dhh
2004-11-24 Initial
277 @@deliveries = []
278 cattr_accessor :deliveries
279
b30eb39f » José Valim and Mikel Lindsaar
2010-01-22 Add more tests to new API.
280 extlib_inheritable_accessor :default_charset
281 self.default_charset = "utf-8"
3fad0cd0 » dhh
2005-02-19 Added support for charsets for both subject and body. The default cha…
282
dcb92536 » José Valim and Mikel Lindsaar
2010-01-22 Add basic template rendering to new DSL.
283 # TODO This should be used when calling render
b30eb39f » José Valim and Mikel Lindsaar
2010-01-22 Add more tests to new API.
284 extlib_inheritable_accessor :default_content_type
285 self.default_content_type = "text/plain"
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
286
b30eb39f » José Valim and Mikel Lindsaar
2010-01-22 Add more tests to new API.
287 extlib_inheritable_accessor :default_mime_version
288 self.default_mime_version = "1.0"
100fd726 » jamis
2005-06-03 Added a "content_type" accessor to allow messages to explicitly speci…
289
c039bcdb » mikel
2009-12-28 Moved sort_parts into Mail, updated mail requirement to 1.4.2
290 # This specifies the order that the parts of a multipart email will be. Usually you put
291 # text/plain at the top so someone without a MIME capable email reader can read the plain
292 # text of your email first.
293 #
294 # Any content type that is not listed here will be inserted in the order you add them to
295 # the email after the content types you list here.
b30eb39f » José Valim and Mikel Lindsaar
2010-01-22 Add more tests to new API.
296 extlib_inheritable_accessor :default_implicit_parts_order
297 self.default_implicit_parts_order = [ "text/plain", "text/enriched", "text/html" ]
5c981528 » jamis
2005-07-01 Better multipart support with implicit multipart/alternative and sort…
298
c34cfcc2 » mikel
2010-01-20 Created mail method for new API
299 # Expose the internal Mail message
300 attr_reader :message
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
301
b30eb39f » José Valim and Mikel Lindsaar
2010-01-22 Add more tests to new API.
302 def headers(args=nil)
303 if args
304 ActiveSupport::Deprecation.warn "headers(Hash) is deprecated, please do headers[key] = value instead", caller
305 @headers = args
306 else
307 @message
308 end
309 end
310
311 def attachments
312 @message.attachments
313 end
43d5504f » josevalim
2009-10-18 Move all render and layout pieces required in ActionMailer from Actio…
314
eda17194 » jamis
2005-07-31 ActionMailer::Base.deliver(email) had been accidentally removed, but …
315 class << self
81c416b7 » josevalim
2009-10-28 More refactoring on ActionMailer::Base.
316
bd5ed651 » technoweenie
2007-11-26 Update ActionMailer so it treats ActionView the same way that ActionC…
317 def mailer_name
318 @mailer_name ||= name.underscore
319 end
0750304c » mikel
2010-01-16 Migrated over to Mail doing delivery.
320 attr_writer :mailer_name
321
322 alias :controller_path :mailer_name
81c416b7 » josevalim
2009-10-28 More refactoring on ActionMailer::Base.
323
59f1df1b » jamis
2005-10-16 Update/extend ActionMailer documentation (rdoc)
324 # Receives a raw email, parses it into an email object, decodes it,
325 # instantiates a new mailer, and passes the email object to the mailer
98dc5827 » lifo
2008-05-25 Merge docrails.
326 # object's +receive+ method. If you want your mailer to be able to
327 # process incoming messages, you'll need to implement a +receive+
59f1df1b » jamis
2005-10-16 Update/extend ActionMailer documentation (rdoc)
328 # method that accepts the email object as a parameter:
329 #
330 # class MyMailer < ActionMailer::Base
331 # def receive(mail)
332 # ...
333 # end
334 # end
704daad7 » josevalim
2010-01-15 Ensure we just send Ruby Stdlib objects in ActionMailer notifications.
335 def receive(raw_mail)
336 ActiveSupport::Notifications.instrument("action_mailer.receive") do |payload|
337 mail = Mail.new(raw_mail)
338 set_payload_for_mail(payload, mail)
2a6bc126 » josevalim
2010-01-13 Add subscriber to ActionMailer.
339 new.receive(mail)
340 end
eda17194 » jamis
2005-07-31 ActionMailer::Base.deliver(email) had been accidentally removed, but …
341 end
342
343 # Deliver the given mail object directly. This can be used to deliver
344 # a preconstructed mail object, like:
345 #
346 # email = MyMailer.create_some_mail(parameters)
347 # email.set_some_obscure_header "frobnicate"
348 # MyMailer.deliver(email)
349 def deliver(mail)
0750304c » mikel
2010-01-16 Migrated over to Mail doing delivery.
350 raise "no mail object available for delivery!" unless mail
351
8b37fee2 » mikel
2010-01-20 Merge branch 'master' of git://github.com/rails/rails
352 ActiveSupport::Notifications.instrument("action_mailer.deliver", :mailer => self.name) do |payload|
353 self.set_payload_for_mail(payload, mail)
354
355 mail.delivery_method delivery_methods[delivery_method],
356 delivery_settings[delivery_method]
e10f51b6 » josevalim
2010-01-19 Refactor delivery methods.
357
8b37fee2 » mikel
2010-01-20 Merge branch 'master' of git://github.com/rails/rails
358 begin
359 # TODO Move me to the instance
0750304c » mikel
2010-01-16 Migrated over to Mail doing delivery.
360 if @@perform_deliveries
dcb92536 » José Valim and Mikel Lindsaar
2010-01-22 Add basic template rendering to new DSL.
361 mail.deliver!
0750304c » mikel
2010-01-16 Migrated over to Mail doing delivery.
362 self.deliveries << mail
363 end
8b37fee2 » mikel
2010-01-20 Merge branch 'master' of git://github.com/rails/rails
364 rescue Exception => e # Net::SMTP errors or sendmail pipe errors
365 raise e if raise_delivery_errors
0750304c » mikel
2010-01-16 Migrated over to Mail doing delivery.
366 end
367 end
368
369 mail
370 end
371
cb21db1a » josh
2008-07-31 Treat ActionMailer template_root as a view path set internally to avo…
372 def template_root
373 self.view_paths && self.view_paths.first
374 end
375
684c2dc2 » josevalim
2009-10-18 Remove ActionMailer helpers and rely on AbstractController one.
376 # Should template root overwrite the whole view_paths?
61c90a4a » NZKoz
2008-01-21 Reapply the TemplateFinder first applied in [8669] then reverted in […
377 def template_root=(root)
cb21db1a » josh
2008-07-31 Treat ActionMailer template_root as a view path set internally to avo…
378 self.view_paths = ActionView::Base.process_view_paths(root)
61c90a4a » NZKoz
2008-01-21 Reapply the TemplateFinder first applied in [8669] then reverted in […
379 end
3cf773b1 » floehopper
2008-08-29 ActionMailer should respond_to? to methods handled by method_missing [#…
380
704daad7 » josevalim
2010-01-15 Ensure we just send Ruby Stdlib objects in ActionMailer notifications.
381 def set_payload_for_mail(payload, mail) #:nodoc:
c905fce3 » josevalim
2010-01-15 Add message_id to AM payload and don't send bcc and cc if they were n…
382 payload[:message_id] = mail.message_id
383 payload[:subject] = mail.subject
384 payload[:to] = mail.to
385 payload[:from] = mail.from
386 payload[:bcc] = mail.bcc if mail.bcc.present?
387 payload[:cc] = mail.cc if mail.cc.present?
388 payload[:date] = mail.date
389 payload[:mail] = mail.encoded
704daad7 » josevalim
2010-01-15 Ensure we just send Ruby Stdlib objects in ActionMailer notifications.
390 end
eda17194 » jamis
2005-07-31 ActionMailer::Base.deliver(email) had been accidentally removed, but …
391 end
392
c34cfcc2 » mikel
2010-01-20 Created mail method for new API
393 def mail(headers = {})
394 # Guard flag to prevent both the old and the new API from firing
bb9d71ff » José Valim and Mikel Lindsaar
2010-01-22 Move class methods to deprecated stuff.
395 # Should be removed when old API is deprecated
c34cfcc2 » mikel
2010-01-20 Created mail method for new API
396 @mail_was_called = true
397 m = @message
398
dcb92536 » José Valim and Mikel Lindsaar
2010-01-22 Add basic template rendering to new DSL.
399 # Get default subject from I18n if none is set
400 headers[:subject] ||= I18n.t(:subject, :scope => [:actionmailer, mailer_name, action_name],
401 :default => action_name.humanize)
402
403 # Give preference to headers and fallbacks to the ones set in mail
1cd55928 » José Valim and Mikel Lindsaar
2010-01-22 First work on implicit multipart.
404 content_type = headers[:content_type] || m.content_type
405 charset = headers[:charset] || m.charset
406 mime_version = headers[:mime_version] || m.mime_version
407 body = nil
408
409 m.subject ||= quote_if_necessary(headers[:subject], charset) if headers[:subject]
410 m.to ||= quote_address_if_necessary(headers[:to], charset) if headers[:to]
411 m.from ||= quote_address_if_necessary(headers[:from], charset) if headers[:from]
412 m.cc ||= quote_address_if_necessary(headers[:cc], charset) if headers[:cc]
413 m.bcc ||= quote_address_if_necessary(headers[:bcc], charset) if headers[:bcc]
414 m.reply_to ||= quote_address_if_necessary(headers[:reply_to], charset) if headers[:reply_to]
415 m.date ||= headers[:date] if headers[:date]
dcb92536 » José Valim and Mikel Lindsaar
2010-01-22 Add basic template rendering to new DSL.
416
417 if block_given?
418 # Do something
419 else
420 # TODO Ensure that we don't need to pass I18n.locale as detail
421 templates = self.class.template_root.find_all(action_name, {}, mailer_name)
422
423 if templates.size == 1
1cd55928 » José Valim and Mikel Lindsaar
2010-01-22 First work on implicit multipart.
424 content_type ||= templates[0].mime_type.to_s
dcb92536 » José Valim and Mikel Lindsaar
2010-01-22 Add basic template rendering to new DSL.
425 m.body = render_to_body(:_template => templates[0])
426 else
1cd55928 » José Valim and Mikel Lindsaar
2010-01-22 First work on implicit multipart.
427 content_type ||= "multipart/alternate"
428
dcb92536 » José Valim and Mikel Lindsaar
2010-01-22 Add basic template rendering to new DSL.
429 templates.each do |template|
430 part = Mail::Part.new
431 part.content_type = template.mime_type.to_s
1cd55928 » José Valim and Mikel Lindsaar
2010-01-22 First work on implicit multipart.
432 part.charset = charset
dcb92536 » José Valim and Mikel Lindsaar
2010-01-22 Add basic template rendering to new DSL.
433 part.body = render_to_body(:_template => template)
1cd55928 » José Valim and Mikel Lindsaar
2010-01-22 First work on implicit multipart.
434 m.add_part(part)
dcb92536 » José Valim and Mikel Lindsaar
2010-01-22 Add basic template rendering to new DSL.
435 end
436 end
437 end
1cd55928 » José Valim and Mikel Lindsaar
2010-01-22 First work on implicit multipart.
438
439 m.content_type = content_type || self.class.default_content_type.dup
440 m.charset = charset || self.class.default_charset.dup
441 m.mime_version = mime_version || self.class.default_mime_version.dup
442
443 # TODO Add me and test me
444 # m.body.set_sort_order(headers[:parts_order] || self.class.default_implicit_parts_order.dup)
445 # m.body.sort_parts!
bb9d71ff » José Valim and Mikel Lindsaar
2010-01-22 Move class methods to deprecated stuff.
446
c34cfcc2 » mikel
2010-01-20 Created mail method for new API
447 m
448 end
449
dcb92536 » José Valim and Mikel Lindsaar
2010-01-22 Add basic template rendering to new DSL.
450 def fill_in_part(part, template, charset)
451
452 end
453
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
454 # Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer
455 # will be initialized according to the named method. If not, the mailer will
456 # remain uninitialized (useful when you only need to invoke the "receive"
457 # method, for instance).
971f4ff8 » josevalim
2009-12-27 DRY ActionMailer code.
458 def initialize(method_name=nil, *args)
d887e46c » jeremy
2009-11-10 Be sure to invoke the super chain! And initialize response body.
459 super()
c34cfcc2 » mikel
2010-01-20 Created mail method for new API
460 @message = Mail.new
4964d3b0 » josevalim
2009-12-22 Make ActionMailer::Base inherit from AbstractController::Base
461 process(method_name, *args) if method_name
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
462 end
463
15d7cac2 » mikel
2009-11-12 Starting again on actionmailer integration with mail
464 # Delivers a Mail object. By default, it delivers the cached mail
98dc5827 » lifo
2008-05-25 Merge docrails.
465 # object (from the <tt>create!</tt> method). If no cached mail object exists, and
eda17194 » jamis
2005-07-31 ActionMailer::Base.deliver(email) had been accidentally removed, but …
466 # no alternate has been given as the parameter, this will fail.
c34cfcc2 » mikel
2010-01-20 Created mail method for new API
467 def deliver!(mail = @message)
0750304c » mikel
2010-01-16 Migrated over to Mail doing delivery.
468 self.class.deliver(mail)
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
469 end
3fad0cd0 » dhh
2005-02-19 Added support for charsets for both subject and body. The default cha…
470
db045dbb » dhh
2004-11-24 Initial
471 end
472 end
Something went wrong with that request. Please try again.