Skip to content
Newer
Older
100644 503 lines (456 sloc) 21.4 KB
a9751a7 @josevalim Refactor ActionMailer layout and remove legacy one.
josevalim authored Oct 17, 2009
1 require 'active_support/core_ext/class'
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
2 require 'active_support/core_ext/module/delegation'
616ebb8 @josevalim Remove unused code paths and require mail only when it's needed.
josevalim authored Dec 28, 2009
3 require 'mail'
a288082 @mikel Adding :transfer_encoding -> :content_transfer_encoding as part of Tm…
mikel authored Dec 30, 2009
4 require 'action_mailer/tmail_compat'
c985a0e Add some tests to collector with templates and any.
José Valim and Mikel Lindsaar authored Jan 23, 2010
5 require 'action_mailer/collector'
a63caa4 Get tests to run (with failures) without old base around
Yehuda Katz + Carl Lerche authored Jun 15, 2009
6
c4590d5 @dhh Fixed docs
dhh authored Mar 28, 2006
7 module ActionMailer #:nodoc:
98dc582 @lifo Merge docrails.
lifo authored May 25, 2008
8 # Action Mailer allows you to send email from your application using a mailer model and views.
db045db @dhh Initial
dhh authored Nov 24, 2004
9 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
10 # = Mailer Models
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
11 #
98dc582 @lifo Merge docrails.
lifo authored May 25, 2008
12 # To use Action Mailer, you need to create a mailer model.
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
13 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
14 # $ script/generate mailer Notifier
15 #
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
16 # The generated model inherits from ActionMailer::Base. Emails are defined by creating methods within the model which are then
17 # used to set variables to be used in the mail template, to change options on the mail, or
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
18 # to add attachments.
19 #
20 # Examples:
21 #
22 # class Notifier < ActionMailer::Base
23 # def signup_notification(recipient)
24 # recipients recipient.email_address_with_name
c3f53f4 @lifo Merge docrails
lifo authored Dec 19, 2008
25 # bcc ["bcc@example.com", "Order Watcher <watcher@example.com>"]
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
26 # from "system@example.com"
27 # subject "New account information"
a037458 @josevalim Bring body(Hash) behavior back.
josevalim authored Jan 19, 2010
28 # body :account => recipient
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
29 # end
30 # end
31 #
32 # Mailer methods have the following configuration methods available.
33 #
34 # * <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.
35 # * <tt>subject</tt> - The subject of your email. Sets the <tt>Subject:</tt> header.
36 # * <tt>from</tt> - Who the email you are sending is from. Sets the <tt>From:</tt> header.
37 # * <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 May 23, 2008
38 # * <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.
39 # * <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 Jan 17, 2010
40 # * <tt>sent_on</tt> - The date on which the message was sent. If not set, the header will be set by the delivery agent.
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
41 # * <tt>content_type</tt> - Specify the content type of the message. Defaults to <tt>text/plain</tt>.
42 # * <tt>headers</tt> - Specify additional headers to be set for the message, e.g. <tt>headers 'X-Mail-Count' => 107370</tt>.
43 #
5c0d38f @dhh Fixed that a return-path header would be ignored (closes #7572) [joost]
dhh authored Mar 27, 2008
44 # When a <tt>headers 'return-path'</tt> is specified, that value will be used as the 'envelope from'
45 # address. Setting this is useful when you want delivery notifications sent to a different address than
46 # the one in <tt>from</tt>.
47 #
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
48 #
49 # = Mailer views
50 #
98dc582 @lifo Merge docrails.
lifo authored May 25, 2008
51 # Like Action Controller, each mailer class has a corresponding view directory
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
52 # in which each method of the class looks for a template with its name.
21187c0 @dhh Apply the rest of Chads patch
dhh authored Feb 21, 2007
53 # To define a template to be used with a mailing, create an <tt>.erb</tt> file with the same name as the method
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
54 # in your mailer model. For example, in the mailer defined above, the template at
21187c0 @dhh Apply the rest of Chads patch
dhh authored Feb 21, 2007
55 # <tt>app/views/notifier/signup_notification.erb</tt> would be used to generate the email.
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
56 #
57 # Variables defined in the model are accessible as instance variables in the view.
58 #
59 # Emails by default are sent in plain text, so a sample view for our model example might look like this:
60 #
61 # Hi <%= @account.name %>,
62 # Thanks for joining our service! Please check back often.
63 #
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
64 # You can even use Action Pack helpers in these views. For example:
65 #
66 # You got a new note!
ee70d1b @josevalim adv_attr_accessors in ActionMailer are not sent to the views, use the…
josevalim authored Dec 25, 2009
67 # <%= truncate(@note.body, 25) %>
68 #
69 # If you need to access the subject, from or the recipients in the view, you can do that through mailer object:
70 #
71 # You got a new note from <%= mailer.from %>!
72 # <%= truncate(@note.body, 25) %>
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
73 #
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
74 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored Apr 21, 2008
75 # = Generating URLs
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
76 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored Apr 21, 2008
77 # URLs can be generated in mailer views using <tt>url_for</tt> or named routes.
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
78 # Unlike controllers from Action Pack, the mailer instance doesn't have any context about the incoming request,
79 # so you'll need to provide all of the details needed to generate a URL.
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
80 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored Apr 21, 2008
81 # When using <tt>url_for</tt> you'll need to provide the <tt>:host</tt>, <tt>:controller</tt>, and <tt>:action</tt>:
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
82 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored Apr 21, 2008
83 # <%= url_for(:host => "example.com", :controller => "welcome", :action => "greeting") %>
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
84 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored Apr 21, 2008
85 # When using named routes you only need to supply the <tt>:host</tt>:
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
86 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored Apr 21, 2008
87 # <%= users_url(:host => "example.com") %>
88 #
89 # You will want to avoid using the <tt>name_of_route_path</tt> form of named routes because it doesn't make sense to
90 # generate relative URLs in email messages.
91 #
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
92 # 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 Apr 21, 2008
93 # the <tt>ActionMailer::Base.default_url_options</tt> hash as follows:
94 #
95 # ActionMailer::Base.default_url_options[:host] = "example.com"
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
96 #
dc4eec1 @lifo Merge docrails:
lifo authored May 9, 2008
97 # 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 Apr 21, 2008
98 #
99 # config.action_mailer.default_url_options = { :host => "example.com" }
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
100 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored Apr 21, 2008
101 # If you do decide to set a default <tt>:host</tt> for your mailers you will want to use the
102 # <tt>:only_path => false</tt> option when using <tt>url_for</tt>. This will ensure that absolute URLs are generated because
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
103 # 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 Apr 21, 2008
104 # explicitly provided.
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
105 #
106 # = Sending mail
107 #
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
108 # Once a mailer action and template are defined, you can deliver your message or create it and save it
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
109 # for delivery later:
110 #
111 # Notifier.deliver_signup_notification(david) # sends the email
112 # mail = Notifier.create_signup_notification(david) # => a tmail object
113 # Notifier.deliver(mail)
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
114 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
115 # You never instantiate your mailer class. Rather, your delivery instance
116 # methods are automatically wrapped in class methods that start with the word
117 # <tt>deliver_</tt> followed by the name of the mailer method that you would
118 # like to deliver. The <tt>signup_notification</tt> method defined above is
119 # delivered by invoking <tt>Notifier.deliver_signup_notification</tt>.
120 #
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
121 #
122 # = HTML email
123 #
21187c0 @dhh Apply the rest of Chads patch
dhh authored Feb 21, 2007
124 # To send mail as HTML, make sure your view (the <tt>.erb</tt> file) generates HTML and
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
125 # set the content type to html.
126 #
127 # class MyMailer < ActionMailer::Base
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored May 29, 2005
128 # def signup_notification(recipient)
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored May 16, 2008
129 # recipients recipient.email_address_with_name
130 # subject "New account information"
131 # from "system@example.com"
132 # body :account => recipient
133 # content_type "text/html"
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored May 29, 2005
134 # end
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
135 # end
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
136 #
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
137 #
138 # = Multipart email
139 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
140 # You can explicitly specify multipart messages:
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored May 29, 2005
141 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
142 # class ApplicationMailer < ActionMailer::Base
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored May 29, 2005
143 # def signup_notification(recipient)
144 # recipients recipient.email_address_with_name
145 # subject "New account information"
146 # from "system@example.com"
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored May 16, 2008
147 # content_type "multipart/alternative"
f00cbf7 @josevalim Bring render_message back for 2.3 compatibility.
josevalim authored Jan 19, 2010
148 # body :account => recipient
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored May 29, 2005
149 #
150 # part :content_type => "text/html",
f00cbf7 @josevalim Bring render_message back for 2.3 compatibility.
josevalim authored Jan 19, 2010
151 # :data => render_message("signup-as-html")
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored May 29, 2005
152 #
153 # part "text/plain" do |p|
f00cbf7 @josevalim Bring render_message back for 2.3 compatibility.
josevalim authored Jan 19, 2010
154 # p.body = render_message("signup-as-plain")
a288082 @mikel Adding :transfer_encoding -> :content_transfer_encoding as part of Tm…
mikel authored Dec 30, 2009
155 # p.content_transfer_encoding = "base64"
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored May 29, 2005
156 # end
157 # end
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
158 # end
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
159 #
98dc582 @lifo Merge docrails.
lifo authored May 25, 2008
160 # Multipart messages can also be used implicitly because Action Mailer will automatically
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
161 # detect and use multipart templates, where each template is named after the name of the action, followed
162 # by the content type. Each such detected template will be added as separate part to the message.
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
163 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
164 # For example, if the following templates existed:
21187c0 @dhh Apply the rest of Chads patch
dhh authored Feb 21, 2007
165 # * signup_notification.text.plain.erb
166 # * signup_notification.text.html.erb
167 # * signup_notification.text.xml.builder
168 # * signup_notification.text.x-yaml.erb
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
169 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
170 # Each would be rendered and added as a separate part to the message,
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored May 16, 2008
171 # with the corresponding content type. The content type for the entire
172 # message is automatically set to <tt>multipart/alternative</tt>, which indicates
173 # that the email contains multiple different representations of the same email
174 # body. The same body hash is passed to each template.
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored May 29, 2005
175 #
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored May 16, 2008
176 # Implicit template rendering is not performed if any attachments or parts have been added to the email.
177 # This means that you'll have to manually add each part to the email and set the content type of the email
178 # to <tt>multipart/alternative</tt>.
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
179 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
180 # = Attachments
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
181 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
182 # Attachments can be added by using the +attachment+ method.
183 #
184 # Example:
185 #
186 # class ApplicationMailer < ActionMailer::Base
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored May 29, 2005
187 # # attachments
188 # def signup_notification(recipient)
189 # recipients recipient.email_address_with_name
190 # subject "New account information"
191 # from "system@example.com"
192 #
193 # attachment :content_type => "image/jpeg",
194 # :body => File.read("an-image.jpg")
195 #
196 # attachment "application/pdf" do |a|
197 # a.body = generate_your_pdf_here()
198 # end
db045db @dhh Initial
dhh authored Nov 24, 2004
199 # end
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
200 # end
c927aa0 @dhh Updated documentation
dhh authored Dec 16, 2004
201 #
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
202 #
c927aa0 @dhh Updated documentation
dhh authored Dec 16, 2004
203 # = Configuration options
204 #
205 # These options are specified on the class level, like <tt>ActionMailer::Base.template_root = "/my/templates"</tt>
206 #
64092de @fxn Improve documentation coverage and markup
fxn authored May 2, 2008
207 # * <tt>template_root</tt> - Determines the base from which template references will be made.
c927aa0 @dhh Updated documentation
dhh authored Dec 16, 2004
208 #
209 # * <tt>logger</tt> - the logger is used for generating information on the mailing run if available.
210 # Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers.
211 #
64092de @fxn Improve documentation coverage and markup
fxn authored May 2, 2008
212 # * <tt>smtp_settings</tt> - Allows detailed configuration for <tt>:smtp</tt> delivery method:
dc4eec1 @lifo Merge docrails:
lifo authored May 9, 2008
213 # * <tt>:address</tt> - Allows you to use a remote mail server. Just change it from its default "localhost" setting.
214 # * <tt>:port</tt> - On the off chance that your mail server doesn't run on port 25, you can change it.
215 # * <tt>:domain</tt> - If you need to specify a HELO domain, you can do it here.
216 # * <tt>:user_name</tt> - If your mail server requires authentication, set the username in this setting.
217 # * <tt>:password</tt> - If your mail server requires authentication, set the password in this setting.
b2504f8 @josh Tidy up ActionMailer rendering logic to take advantage of view path c…
josh authored Aug 6, 2008
218 # * <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 May 16, 2008
219 # This is a symbol and one of <tt>:plain</tt>, <tt>:login</tt>, <tt>:cram_md5</tt>.
c2e7851 @josevalim Add ActionMailer::Base#enable_starttls_auto option for enabling/disab…
josevalim authored Jan 11, 2009
220 # * <tt>:enable_starttls_auto</tt> - When set to true, detects if STARTTLS is enabled in your SMTP server and starts to use it.
221 # It works only on Ruby >= 1.8.7 and Ruby >= 1.9. Default is true.
c927aa0 @dhh Updated documentation
dhh authored Dec 16, 2004
222 #
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored May 16, 2008
223 # * <tt>sendmail_settings</tt> - Allows you to override options for the <tt>:sendmail</tt> delivery method.
224 # * <tt>:location</tt> - The location of the sendmail executable. Defaults to <tt>/usr/sbin/sendmail</tt>.
225 # * <tt>:arguments</tt> - The command line arguments. Defaults to <tt>-i -t</tt>.
dc4eec1 @lifo Merge docrails:
lifo authored May 9, 2008
226 #
fbe6c3c @edavis10 Adds a :file delivery_method to save email to a file on disk
edavis10 authored Aug 7, 2009
227 # * <tt>file_settings</tt> - Allows you to override options for the <tt>:file</tt> delivery method.
228 # * <tt>:location</tt> - The directory into which emails will be written. Defaults to the application <tt>tmp/mails</tt>.
229 #
dc4eec1 @lifo Merge docrails:
lifo authored May 9, 2008
230 # * <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 Dec 16, 2004
231 #
fbe6c3c @edavis10 Adds a :file delivery_method to save email to a file on disk
edavis10 authored Aug 8, 2009
232 # * <tt>delivery_method</tt> - Defines a delivery method. Possible values are <tt>:smtp</tt> (default), <tt>:sendmail</tt>, <tt>:test</tt>,
f4f7677 @matthewrudy abstract all of the ActionMailer delivery methods into their own clas…
matthewrudy authored Oct 28, 2009
233 # and <tt>:file</tt>. Or you may provide a custom delivery method object eg. MyOwnDeliveryMethodClass.new
c927aa0 @dhh Updated documentation
dhh authored Dec 16, 2004
234 #
dc4eec1 @lifo Merge docrails:
lifo authored May 9, 2008
235 # * <tt>perform_deliveries</tt> - Determines whether <tt>deliver_*</tt> methods are actually carried out. By default they are,
c927aa0 @dhh Updated documentation
dhh authored Dec 16, 2004
236 # but this can be turned off to help functional testing.
237 #
64092de @fxn Improve documentation coverage and markup
fxn authored May 2, 2008
238 # * <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 Dec 16, 2004
239 # for unit and functional testing.
af56c80 @dhh Updated documentation
dhh authored Feb 24, 2005
240 #
b2504f8 @josh Tidy up ActionMailer rendering logic to take advantage of view path c…
josh authored Aug 7, 2008
241 # * <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 May 16, 2008
242 # pick a different charset from inside a method with +charset+.
c2e7851 @josevalim Add ActionMailer::Base#enable_starttls_auto option for enabling/disab…
josevalim authored Jan 11, 2009
243 #
475bd74 @dhh Fix docs (closes #2598)
dhh authored Oct 26, 2005
244 # * <tt>default_content_type</tt> - The default content type used for the main part of the message. Defaults to "text/plain". You
b2504f8 @josh Tidy up ActionMailer rendering logic to take advantage of view path c…
josh authored Aug 7, 2008
245 # can also pick a different content type from inside a method with +content_type+.
c2e7851 @josevalim Add ActionMailer::Base#enable_starttls_auto option for enabling/disab…
josevalim authored Jan 11, 2009
246 #
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored May 16, 2008
247 # * <tt>default_mime_version</tt> - The default mime version used for the message. Defaults to <tt>1.0</tt>. You
248 # can also pick a different value from inside a method with +mime_version+.
c2e7851 @josevalim Add ActionMailer::Base#enable_starttls_auto option for enabling/disab…
josevalim authored Jan 11, 2009
249 #
475bd74 @dhh Fix docs (closes #2598)
dhh authored Oct 26, 2005
250 # * <tt>default_implicit_parts_order</tt> - When a message is built implicitly (i.e. multiple parts are assembled from templates
5c98152 @jamis Better multipart support with implicit multipart/alternative and sort…
jamis authored Jul 1, 2005
251 # 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 May 16, 2008
252 # <tt>["text/html", "text/enriched", "text/plain"]</tt>. Items that appear first in the array have higher priority in the mail client
5c98152 @jamis Better multipart support with implicit multipart/alternative and sort…
jamis authored Jul 1, 2005
253 # 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 May 16, 2008
254 # +implicit_parts_order+.
4964d3b @josevalim Make ActionMailer::Base inherit from AbstractController::Base
josevalim authored Dec 22, 2009
255 class Base < AbstractController::Base
47e5caa @josevalim Merge Mail with latest Rails and move mail gem to Gemfile.
josevalim authored Dec 27, 2009
256 include Quoting
a9751a7 @josevalim Refactor ActionMailer layout and remove legacy one.
josevalim authored Oct 17, 2009
257
c03c40b @josevalim Expose a _render_partial hook as thhe _render_template one and make u…
josevalim authored Dec 31, 2009
258 include AbstractController::Logger
83f4d86 @dhh Rename the RenderingController module to just plain Rendering
dhh authored Dec 20, 2009
259 include AbstractController::Rendering
976c264 @josevalim Extracted localized_cache.rb from ActionController, added it to Abstr…
josevalim authored Oct 28, 2009
260 include AbstractController::LocalizedCache
a9751a7 @josevalim Refactor ActionMailer layout and remove legacy one.
josevalim authored Oct 17, 2009
261 include AbstractController::Layouts
684c2dc @josevalim Remove ActionMailer helpers and rely on AbstractController one.
josevalim authored Oct 18, 2009
262 include AbstractController::Helpers
f564f94 @josevalim Remove duplicated url_for code and move methods shared between Action…
josevalim authored Jan 7, 2010
263 include AbstractController::UrlFor
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored May 29, 2005
264
ee70d1b @josevalim adv_attr_accessors in ActionMailer are not sent to the views, use the…
josevalim authored Dec 25, 2009
265 helper ActionMailer::MailHelper
10c509f @mikel Moved old API into deprecated_api.rb in preparation for new Rails 3 M…
mikel authored Jan 20, 2010
266 include ActionMailer::DeprecatedApi
418c3f8 @josevalim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored Oct 21, 2009
267
e10f51b @josevalim Refactor delivery methods.
josevalim authored Jan 19, 2010
268 include ActionMailer::DeliveryMethods
269
c927aa0 @dhh Updated documentation
dhh authored Dec 16, 2004
270 private_class_method :new #:nodoc:
db045db @dhh Initial
dhh authored Nov 24, 2004
271
272 @@raise_delivery_errors = true
273 cattr_accessor :raise_delivery_errors
274
275 @@perform_deliveries = true
276 cattr_accessor :perform_deliveries
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
277
db045db @dhh Initial
dhh authored Nov 24, 2004
278 @@deliveries = []
279 cattr_accessor :deliveries
280
b30eb39 Add more tests to new API.
José Valim and Mikel Lindsaar authored Jan 22, 2010
281 extlib_inheritable_accessor :default_charset
282 self.default_charset = "utf-8"
3fad0cd @dhh Added support for charsets for both subject and body. The default cha…
dhh authored Feb 19, 2005
283
dcb9253 Add basic template rendering to new DSL.
José Valim and Mikel Lindsaar authored Jan 22, 2010
284 # TODO This should be used when calling render
b30eb39 Add more tests to new API.
José Valim and Mikel Lindsaar authored Jan 22, 2010
285 extlib_inheritable_accessor :default_content_type
286 self.default_content_type = "text/plain"
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
287
b30eb39 Add more tests to new API.
José Valim and Mikel Lindsaar authored Jan 22, 2010
288 extlib_inheritable_accessor :default_mime_version
289 self.default_mime_version = "1.0"
100fd72 @jamis Added a "content_type" accessor to allow messages to explicitly speci…
jamis authored Jun 3, 2005
290
c039bcd @mikel Moved sort_parts into Mail, updated mail requirement to 1.4.2
mikel authored Dec 28, 2009
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.
b30eb39 Add more tests to new API.
José Valim and Mikel Lindsaar authored Jan 22, 2010
297 extlib_inheritable_accessor :default_implicit_parts_order
298 self.default_implicit_parts_order = [ "text/plain", "text/enriched", "text/html" ]
5c98152 @jamis Better multipart support with implicit multipart/alternative and sort…
jamis authored Jul 1, 2005
299
c34cfcc @mikel Created mail method for new API
mikel authored Jan 20, 2010
300 # Expose the internal Mail message
c6b1626 Added basic explicit multipart rendering and tests
José Valim and Mikel Lindsaar authored Jan 23, 2010
301 # TODO: Make this an _internal ivar?
c34cfcc @mikel Created mail method for new API
mikel authored Jan 20, 2010
302 attr_reader :message
c6b1626 Added basic explicit multipart rendering and tests
José Valim and Mikel Lindsaar authored Jan 23, 2010
303
b30eb39 Add more tests to new API.
José Valim and Mikel Lindsaar authored Jan 22, 2010
304 def headers(args=nil)
305 if args
306 ActiveSupport::Deprecation.warn "headers(Hash) is deprecated, please do headers[key] = value instead", caller
307 @headers = args
308 else
309 @message
310 end
311 end
312
313 def attachments
314 @message.attachments
315 end
43d5504 @josevalim Move all render and layout pieces required in ActionMailer from Actio…
josevalim authored Oct 18, 2009
316
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but …
jamis authored Jul 31, 2005
317 class << self
81c416b @josevalim More refactoring on ActionMailer::Base.
josevalim authored Oct 28, 2009
318
bd5ed65 @technoweenie Update ActionMailer so it treats ActionView the same way that ActionC…
technoweenie authored Nov 26, 2007
319 def mailer_name
320 @mailer_name ||= name.underscore
321 end
0750304 @mikel Migrated over to Mail doing delivery.
mikel authored Jan 16, 2010
322 attr_writer :mailer_name
323
324 alias :controller_path :mailer_name
81c416b @josevalim More refactoring on ActionMailer::Base.
josevalim authored Oct 28, 2009
325
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored Oct 16, 2005
326 # Receives a raw email, parses it into an email object, decodes it,
327 # instantiates a new mailer, and passes the email object to the mailer
98dc582 @lifo Merge docrails.
lifo authored May 25, 2008
328 # object's +receive+ method. If you want your mailer to be able to
329 # process incoming messages, you'll need to implement a +receive+
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored Oct 16, 2005
330 # method that accepts the email object as a parameter:
331 #
332 # class MyMailer < ActionMailer::Base
333 # def receive(mail)
334 # ...
335 # end
336 # end
704daad @josevalim Ensure we just send Ruby Stdlib objects in ActionMailer notifications.
josevalim authored Jan 15, 2010
337 def receive(raw_mail)
338 ActiveSupport::Notifications.instrument("action_mailer.receive") do |payload|
339 mail = Mail.new(raw_mail)
340 set_payload_for_mail(payload, mail)
2a6bc12 @josevalim Add subscriber to ActionMailer.
josevalim authored Jan 13, 2010
341 new.receive(mail)
342 end
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but …
jamis authored Jul 31, 2005
343 end
344
345 # Deliver the given mail object directly. This can be used to deliver
346 # a preconstructed mail object, like:
347 #
348 # email = MyMailer.create_some_mail(parameters)
349 # email.set_some_obscure_header "frobnicate"
350 # MyMailer.deliver(email)
351 def deliver(mail)
0750304 @mikel Migrated over to Mail doing delivery.
mikel authored Jan 16, 2010
352 raise "no mail object available for delivery!" unless mail
353
8b37fee @mikel Merge branch 'master' of git://github.com/rails/rails
mikel authored Jan 20, 2010
354 ActiveSupport::Notifications.instrument("action_mailer.deliver", :mailer => self.name) do |payload|
355 self.set_payload_for_mail(payload, mail)
356
357 mail.delivery_method delivery_methods[delivery_method],
358 delivery_settings[delivery_method]
e10f51b @josevalim Refactor delivery methods.
josevalim authored Jan 19, 2010
359
8b37fee @mikel Merge branch 'master' of git://github.com/rails/rails
mikel authored Jan 20, 2010
360 begin
361 # TODO Move me to the instance
0750304 @mikel Migrated over to Mail doing delivery.
mikel authored Jan 16, 2010
362 if @@perform_deliveries
dcb9253 Add basic template rendering to new DSL.
José Valim and Mikel Lindsaar authored Jan 22, 2010
363 mail.deliver!
0750304 @mikel Migrated over to Mail doing delivery.
mikel authored Jan 16, 2010
364 self.deliveries << mail
365 end
8b37fee @mikel Merge branch 'master' of git://github.com/rails/rails
mikel authored Jan 20, 2010
366 rescue Exception => e # Net::SMTP errors or sendmail pipe errors
367 raise e if raise_delivery_errors
0750304 @mikel Migrated over to Mail doing delivery.
mikel authored Jan 16, 2010
368 end
369 end
370
371 mail
372 end
373
cb21db1 @josh Treat ActionMailer template_root as a view path set internally to avo…
josh authored Jul 31, 2008
374 def template_root
375 self.view_paths && self.view_paths.first
376 end
377
684c2dc @josevalim Remove ActionMailer helpers and rely on AbstractController one.
josevalim authored Oct 18, 2009
378 # Should template root overwrite the whole view_paths?
61c90a4 @NZKoz Reapply the TemplateFinder first applied in [8669] then reverted in […
NZKoz authored Jan 21, 2008
379 def template_root=(root)
cb21db1 @josh Treat ActionMailer template_root as a view path set internally to avo…
josh authored Aug 1, 2008
380 self.view_paths = ActionView::Base.process_view_paths(root)
61c90a4 @NZKoz Reapply the TemplateFinder first applied in [8669] then reverted in […
NZKoz authored Jan 21, 2008
381 end
3cf773b @floehopper ActionMailer should respond_to? to methods handled by method_missing [#…
floehopper authored Aug 29, 2008
382
704daad @josevalim Ensure we just send Ruby Stdlib objects in ActionMailer notifications.
josevalim authored Jan 15, 2010
383 def set_payload_for_mail(payload, mail) #:nodoc:
c905fce @josevalim Add message_id to AM payload and don't send bcc and cc if they were n…
josevalim authored Jan 15, 2010
384 payload[:message_id] = mail.message_id
385 payload[:subject] = mail.subject
386 payload[:to] = mail.to
387 payload[:from] = mail.from
388 payload[:bcc] = mail.bcc if mail.bcc.present?
389 payload[:cc] = mail.cc if mail.cc.present?
390 payload[:date] = mail.date
391 payload[:mail] = mail.encoded
704daad @josevalim Ensure we just send Ruby Stdlib objects in ActionMailer notifications.
josevalim authored Jan 15, 2010
392 end
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but …
jamis authored Jul 31, 2005
393 end
394
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
395 # Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer
396 # will be initialized according to the named method. If not, the mailer will
397 # remain uninitialized (useful when you only need to invoke the "receive"
398 # method, for instance).
399 def initialize(method_name=nil, *args)
400 super()
401 @message = Mail.new
402 process(method_name, *args) if method_name
403 end
404
405 # Delivers a Mail object. By default, it delivers the cached mail
406 # object (from the <tt>create!</tt> method). If no cached mail object exists, and
407 # no alternate has been given as the parameter, this will fail.
408 def deliver!(mail = @message)
409 self.class.deliver(mail)
410 end
411
951397b Get implicit multipart and attachments working together.
José Valim and Mikel Lindsaar authored Jan 22, 2010
412 # TODO Add new delivery method goodness
c34cfcc @mikel Created mail method for new API
mikel authored Jan 20, 2010
413 def mail(headers = {})
414 # Guard flag to prevent both the old and the new API from firing
bb9d71f Move class methods to deprecated stuff.
José Valim and Mikel Lindsaar authored Jan 22, 2010
415 # Should be removed when old API is deprecated
c34cfcc @mikel Created mail method for new API
mikel authored Jan 20, 2010
416 @mail_was_called = true
417
e7e4ed4 Set sort order for explicit parts from the collector's template sequence
José Valim and Mikel Lindsaar authored Jan 24, 2010
418 m = @message
dcb9253 Add basic template rendering to new DSL.
José Valim and Mikel Lindsaar authored Jan 22, 2010
419
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
420 # Give preference to headers and fallback to the ones set in mail
1cd5592 First work on implicit multipart.
José Valim and Mikel Lindsaar authored Jan 22, 2010
421 content_type = headers[:content_type] || m.content_type
951397b Get implicit multipart and attachments working together.
José Valim and Mikel Lindsaar authored Jan 22, 2010
422 charset = headers[:charset] || m.charset || self.class.default_charset.dup
423 mime_version = headers[:mime_version] || m.mime_version || self.class.default_mime_version.dup
1cd5592 First work on implicit multipart.
José Valim and Mikel Lindsaar authored Jan 22, 2010
424
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
425 headers[:subject] ||= default_subject
426 quote_fields(m, headers, charset)
dcb9253 Add basic template rendering to new DSL.
José Valim and Mikel Lindsaar authored Jan 22, 2010
427
e7e4ed4 Set sort order for explicit parts from the collector's template sequence
José Valim and Mikel Lindsaar authored Jan 23, 2010
428 sort_order = headers[:parts_order] || self.class.default_implicit_parts_order.dup
429
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
430 responses = if headers[:body]
431 [ { :body => headers[:body], :content_type => self.class.default_content_type.dup } ]
c6b1626 Added basic explicit multipart rendering and tests
José Valim and Mikel Lindsaar authored Jan 23, 2010
432 elsif block_given?
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
433 collector = ActionMailer::Collector.new(self) { render(action_name) }
434 yield(collector)
e7e4ed4 Set sort order for explicit parts from the collector's template sequence
José Valim and Mikel Lindsaar authored Jan 23, 2010
435 # Collect the sort order of the parts from the collector as Mail will always
436 # sort parts on encode into a "sane" sequence.
437 sort_order = collector.responses.map { |r| r[:content_type] }
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
438 collector.responses
dcb9253 Add basic template rendering to new DSL.
José Valim and Mikel Lindsaar authored Jan 22, 2010
439 else
440 # TODO Ensure that we don't need to pass I18n.locale as detail
5c3ef8c Refactor subject with i18n.
José Valim and Mikel Lindsaar authored Jan 23, 2010
441 templates = self.class.template_root.find_all(action_name, {}, self.class.mailer_name)
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
442
443 templates.map do |template|
444 { :body => render_to_body(:_template => template),
445 :content_type => template.mime_type.to_s }
dcb9253 Add basic template rendering to new DSL.
José Valim and Mikel Lindsaar authored Jan 22, 2010
446 end
447 end
951397b Get implicit multipart and attachments working together.
José Valim and Mikel Lindsaar authored Jan 22, 2010
448
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
449 content_type ||= create_parts_from_responses(m, responses, charset)
450 m.content_type = content_type
951397b Get implicit multipart and attachments working together.
José Valim and Mikel Lindsaar authored Jan 22, 2010
451 m.charset = charset
452 m.mime_version = mime_version
453
e7e4ed4 Set sort order for explicit parts from the collector's template sequence
José Valim and Mikel Lindsaar authored Jan 23, 2010
454 if m.multipart?
455 m.body.set_sort_order(sort_order)
951397b Get implicit multipart and attachments working together.
José Valim and Mikel Lindsaar authored Jan 22, 2010
456 m.body.sort_parts!
457 end
bb9d71f Move class methods to deprecated stuff.
José Valim and Mikel Lindsaar authored Jan 22, 2010
458
c34cfcc @mikel Created mail method for new API
mikel authored Jan 20, 2010
459 m
460 end
461
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
462 protected
463
464 def default_subject #:nodoc:
5c3ef8c Refactor subject with i18n.
José Valim and Mikel Lindsaar authored Jan 23, 2010
465 mailer_scope = self.class.mailer_name.gsub('/', '.')
466 I18n.t(:subject, :scope => [:actionmailer, mailer_scope, action_name], :default => action_name.humanize)
467 end
468
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
469 def quote_fields(m, headers, charset) #:nodoc:
470 m.subject ||= quote_if_necessary(headers[:subject], charset) if headers[:subject]
471 m.to ||= quote_address_if_necessary(headers[:to], charset) if headers[:to]
472 m.from ||= quote_address_if_necessary(headers[:from], charset) if headers[:from]
473 m.cc ||= quote_address_if_necessary(headers[:cc], charset) if headers[:cc]
474 m.bcc ||= quote_address_if_necessary(headers[:bcc], charset) if headers[:bcc]
475 m.reply_to ||= quote_address_if_necessary(headers[:reply_to], charset) if headers[:reply_to]
476 m.date ||= headers[:date] if headers[:date]
dcb9253 Add basic template rendering to new DSL.
José Valim and Mikel Lindsaar authored Jan 22, 2010
477 end
478
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
479 def create_parts_from_responses(m, responses, charset) #:nodoc:
480 if responses.size == 1 && !m.has_attachments?
481 m.body = responses[0][:body]
482 return responses[0][:content_type]
483 elsif responses.size > 1 && m.has_attachments?
484 container = Mail::Part.new
485 container.content_type = "multipart/alternate"
486 responses.each { |r| insert_part(container, r, charset) }
487 m.add_part(container)
488 else
489 responses.each { |r| insert_part(m, r, charset) }
490 end
491
492 m.has_attachments? ? "multipart/mixed" : "multipart/alternate"
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored May 29, 2005
493 end
494
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
495 def insert_part(container, response, charset) #:nodoc:
496 response[:charset] ||= charset
497 part = Mail::Part.new(response)
498 container.add_part(part)
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored May 29, 2005
499 end
3fad0cd @dhh Added support for charsets for both subject and body. The default cha…
dhh authored Feb 19, 2005
500
db045db @dhh Initial
dhh authored Nov 24, 2004
501 end
502 end
Something went wrong with that request. Please try again.