Skip to content
This repository
Newer
Older
100644 732 lines (643 sloc) 29.068 kb
a63caa4c » Yehuda Katz + Carl Lerche
2009-06-15 Get tests to run (with failures) without old base around
1 require "active_support/core_ext/class"
5314abed » Yehuda Katz + Carl Lerche
2009-06-15 Keep ActionMailer using the old layouts code until it gets refactored.
2 # Use the old layouts until actionmailer gets refactored
3 require "action_controller/old_base/layout"
a63caa4c » Yehuda Katz + Carl Lerche
2009-06-15 Get tests to run (with failures) without old base around
4
c4590d57 » dhh
2006-03-28 Fixed docs
5 module ActionMailer #:nodoc:
98dc5827 » lifo
2008-05-25 Merge docrails.
6 # Action Mailer allows you to send email from your application using a mailer model and views.
db045dbb » dhh
2004-11-24 Initial
7 #
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
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"
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
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.
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
39 # * <tt>sent_on</tt> - The date on which the message was sent. If not set, the header wil be set by the delivery agent.
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 #
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
47 # The <tt>body</tt> method has special behavior. It takes a hash which generates an instance variable
48 # named after each key in the hash containing the value that that key points to.
49 #
5c0d38f6 » dhh
2008-03-27 Fixed that a return-path header would be ignored (closes #7572) [joost]
50 # So, for example, <tt>body :account => recipient</tt> would result
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
51 # in an instance variable <tt>@account</tt> with the value of <tt>recipient</tt> being accessible in the
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
52 # view.
53 #
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
54 #
55 # = Mailer views
56 #
98dc5827 » lifo
2008-05-25 Merge docrails.
57 # 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, …
58 # 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
59 # 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…
60 # 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
61 # <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, …
62 #
63 # Variables defined in the model are accessible as instance variables in the view.
64 #
65 # Emails by default are sent in plain text, so a sample view for our model example might look like this:
66 #
67 # Hi <%= @account.name %>,
68 # Thanks for joining our service! Please check back often.
69 #
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
70 # You can even use Action Pack helpers in these views. For example:
71 #
72 # You got a new note!
73 # <%= truncate(note.body, 25) %>
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
74 #
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
75 #
4809dcc1 » Cody Fauser
2008-04-21 * Remove default_url_options from mailer generator
76 # = Generating URLs
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
77 #
4809dcc1 » Cody Fauser
2008-04-21 * Remove default_url_options from mailer generator
78 # 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…
79 # Unlike controllers from Action Pack, the mailer instance doesn't have any context about the incoming request,
80 # so you'll need to provide all of the details needed to generate a URL.
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
81 #
4809dcc1 » Cody Fauser
2008-04-21 * Remove default_url_options from mailer generator
82 # 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…
83 #
4809dcc1 » Cody Fauser
2008-04-21 * Remove default_url_options from mailer generator
84 # <%= url_for(:host => "example.com", :controller => "welcome", :action => "greeting") %>
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
85 #
4809dcc1 » Cody Fauser
2008-04-21 * Remove default_url_options from mailer generator
86 # 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…
87 #
4809dcc1 » Cody Fauser
2008-04-21 * Remove default_url_options from mailer generator
88 # <%= users_url(:host => "example.com") %>
89 #
90 # You will want to avoid using the <tt>name_of_route_path</tt> form of named routes because it doesn't make sense to
91 # generate relative URLs in email messages.
92 #
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
93 # 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
94 # the <tt>ActionMailer::Base.default_url_options</tt> hash as follows:
95 #
96 # ActionMailer::Base.default_url_options[:host] = "example.com"
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
97 #
dc4eec11 » lifo
2008-05-09 Merge docrails:
98 # 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
99 #
100 # config.action_mailer.default_url_options = { :host => "example.com" }
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
101 #
4809dcc1 » Cody Fauser
2008-04-21 * Remove default_url_options from mailer generator
102 # If you do decide to set a default <tt>:host</tt> for your mailers you will want to use the
103 # <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…
104 # 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
105 # explicitly provided.
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
106 #
107 # = Sending mail
108 #
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
109 # 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, …
110 # for delivery later:
111 #
112 # Notifier.deliver_signup_notification(david) # sends the email
113 # mail = Notifier.create_signup_notification(david) # => a tmail object
114 # Notifier.deliver(mail)
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
115 #
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
116 # You never instantiate your mailer class. Rather, your delivery instance
117 # methods are automatically wrapped in class methods that start with the word
118 # <tt>deliver_</tt> followed by the name of the mailer method that you would
119 # like to deliver. The <tt>signup_notification</tt> method defined above is
120 # delivered by invoking <tt>Notifier.deliver_signup_notification</tt>.
121 #
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
122 #
123 # = HTML email
124 #
21187c0f » dhh
2007-02-21 Apply the rest of Chads patch
125 # 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, …
126 # set the content type to html.
127 #
128 # class MyMailer < ActionMailer::Base
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
129 # def signup_notification(recipient)
46f30f90 » lifo
2008-05-16 Merge documentation changes from docrails.
130 # recipients recipient.email_address_with_name
131 # subject "New account information"
132 # from "system@example.com"
133 # body :account => recipient
134 # content_type "text/html"
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
135 # end
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
136 # end
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
137 #
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
138 #
139 # = Multipart email
140 #
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
141 # You can explicitly specify multipart messages:
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
142 #
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
143 # class ApplicationMailer < ActionMailer::Base
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
144 # def signup_notification(recipient)
145 # recipients recipient.email_address_with_name
146 # subject "New account information"
147 # from "system@example.com"
46f30f90 » lifo
2008-05-16 Merge documentation changes from docrails.
148 # content_type "multipart/alternative"
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
149 #
150 # part :content_type => "text/html",
151 # :body => render_message("signup-as-html", :account => recipient)
152 #
153 # part "text/plain" do |p|
154 # p.body = render_message("signup-as-plain", :account => recipient)
155 # p.transfer_encoding = "base64"
156 # end
157 # end
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
158 # end
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
159 #
98dc5827 » lifo
2008-05-25 Merge docrails.
160 # 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, …
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.
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
163 #
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
164 # For example, if the following templates existed:
21187c0f » dhh
2007-02-21 Apply the rest of Chads patch
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
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
169 #
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
170 # Each would be rendered and added as a separate part to the message,
46f30f90 » lifo
2008-05-16 Merge documentation changes from docrails.
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.
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
175 #
46f30f90 » lifo
2008-05-16 Merge documentation changes from docrails.
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>.
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
179 #
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
180 # = Attachments
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
181 #
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
182 # Attachments can be added by using the +attachment+ method.
183 #
184 # Example:
185 #
186 # class ApplicationMailer < ActionMailer::Base
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
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
db045dbb » dhh
2004-11-24 Initial
199 # end
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
200 # end
c927aa0f » dhh
2004-12-16 Updated documentation
201 #
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
202 #
c927aa0f » dhh
2004-12-16 Updated documentation
203 # = Configuration options
204 #
205 # These options are specified on the class level, like <tt>ActionMailer::Base.template_root = "/my/templates"</tt>
206 #
64092de2 » fxn
2008-05-02 Improve documentation coverage and markup
207 # * <tt>template_root</tt> - Determines the base from which template references will be made.
c927aa0f » dhh
2004-12-16 Updated documentation
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 #
64092de2 » fxn
2008-05-02 Improve documentation coverage and markup
212 # * <tt>smtp_settings</tt> - Allows detailed configuration for <tt>:smtp</tt> delivery method:
dc4eec11 » lifo
2008-05-09 Merge docrails:
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.
b2504f8b » josh
2008-08-06 Tidy up ActionMailer rendering logic to take advantage of view path c…
218 # * <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.
219 # 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…
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.
c927aa0f » dhh
2004-12-16 Updated documentation
222 #
46f30f90 » lifo
2008-05-16 Merge documentation changes from docrails.
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>.
dc4eec11 » lifo
2008-05-09 Merge docrails:
226 #
227 # * <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
228 #
64092de2 » fxn
2008-05-02 Improve documentation coverage and markup
229 # * <tt>delivery_method</tt> - Defines a delivery method. Possible values are <tt>:smtp</tt> (default), <tt>:sendmail</tt>, and <tt>:test</tt>.
c927aa0f » dhh
2004-12-16 Updated documentation
230 #
dc4eec11 » lifo
2008-05-09 Merge docrails:
231 # * <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
232 # but this can be turned off to help functional testing.
233 #
64092de2 » fxn
2008-05-02 Improve documentation coverage and markup
234 # * <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
235 # for unit and functional testing.
af56c806 » dhh
2005-02-24 Updated documentation
236 #
b2504f8b » josh
2008-08-06 Tidy up ActionMailer rendering logic to take advantage of view path c…
237 # * <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.
238 # 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…
239 #
475bd741 » dhh
2005-10-26 Fix docs (closes #2598)
240 # * <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…
241 # 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…
242 #
46f30f90 » lifo
2008-05-16 Merge documentation changes from docrails.
243 # * <tt>default_mime_version</tt> - The default mime version used for the message. Defaults to <tt>1.0</tt>. You
244 # 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…
245 #
475bd741 » dhh
2005-10-26 Fix docs (closes #2598)
246 # * <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…
247 # 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.
248 # <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…
249 # 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.
250 # +implicit_parts_order+.
db045dbb » dhh
2004-11-24 Initial
251 class Base
e201fc75 » josh
2008-11-23 use autoload instead of explicit requires for ActionMailer
252 include AdvAttrAccessor, PartContainer, Quoting, Utils
6228220c » dhh
2008-09-09 Revert "Revert "Add layout functionality to mailers.""
253 if Object.const_defined?(:ActionController)
254 include ActionController::UrlWriter
5314abed » Yehuda Katz + Carl Lerche
2009-06-15 Keep ActionMailer using the old layouts code until it gets refactored.
255 include ActionController::Layout
6228220c » dhh
2008-09-09 Revert "Revert "Add layout functionality to mailers.""
256 end
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
257
c927aa0f » dhh
2004-12-16 Updated documentation
258 private_class_method :new #:nodoc:
db045dbb » dhh
2004-11-24 Initial
259
cb21db1a » josh
2008-07-31 Treat ActionMailer template_root as a view path set internally to avo…
260 class_inheritable_accessor :view_paths
441e4e22 » svenfuchs
2009-02-22 load plugin view_paths to action_mailer view_paths and make action_ma…
261 self.view_paths = []
262
db045dbb » dhh
2004-11-24 Initial
263 cattr_accessor :logger
264
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
265 @@smtp_settings = {
c2e7851f » josevalim
2009-01-11 Add ActionMailer::Base#enable_starttls_auto option for enabling/disab…
266 :address => "localhost",
267 :port => 25,
268 :domain => 'localhost.localdomain',
269 :user_name => nil,
270 :password => nil,
271 :authentication => nil,
272 :enable_starttls_auto => true,
db045dbb » dhh
2004-11-24 Initial
273 }
27bb903a » NZKoz
2007-01-31 Rename server_settings to smtp_settings, add sendmail_settings to all…
274 cattr_accessor :smtp_settings
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
275
27bb903a » NZKoz
2007-01-31 Rename server_settings to smtp_settings, add sendmail_settings to all…
276 @@sendmail_settings = {
277 :location => '/usr/sbin/sendmail',
278 :arguments => '-i -t'
279 }
280 cattr_accessor :sendmail_settings
db045dbb » dhh
2004-11-24 Initial
281
282 @@raise_delivery_errors = true
283 cattr_accessor :raise_delivery_errors
284
57cde631 » dhh
2007-11-07 Allow ActionMailer subclasses to individually set their delivery meth…
285 superclass_delegating_accessor :delivery_method
286 self.delivery_method = :smtp
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
287
db045dbb » dhh
2004-11-24 Initial
288 @@perform_deliveries = true
289 cattr_accessor :perform_deliveries
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
290
db045dbb » dhh
2004-11-24 Initial
291 @@deliveries = []
292 cattr_accessor :deliveries
293
3fad0cd0 » dhh
2005-02-19 Added support for charsets for both subject and body. The default cha…
294 @@default_charset = "utf-8"
295 cattr_accessor :default_charset
296
100fd726 » jamis
2005-06-03 Added a "content_type" accessor to allow messages to explicitly speci…
297 @@default_content_type = "text/plain"
298 cattr_accessor :default_content_type
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
299
45b5555f » jamis
2006-09-09 Make mime version default to 1.0. closes #2323
300 @@default_mime_version = "1.0"
dca4d4e8 » jamis
2005-08-22 Multipart messages specify a MIME-Version header automatically #2003
301 cattr_accessor :default_mime_version
100fd726 » jamis
2005-06-03 Added a "content_type" accessor to allow messages to explicitly speci…
302
5c981528 » jamis
2005-07-01 Better multipart support with implicit multipart/alternative and sort…
303 @@default_implicit_parts_order = [ "text/html", "text/enriched", "text/plain" ]
304 cattr_accessor :default_implicit_parts_order
305
28bf2fa0 » josh
2008-09-28 Protect body ivar from being clobbered by the mailer template assigns
306 cattr_reader :protected_instance_variables
307 @@protected_instance_variables = %w(@body)
308
59f1df1b » jamis
2005-10-16 Update/extend ActionMailer documentation (rdoc)
309 # Specify the BCC addresses for the message
310 adv_attr_accessor :bcc
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
311
59f1df1b » jamis
2005-10-16 Update/extend ActionMailer documentation (rdoc)
312 # Define the body of the message. This is either a Hash (in which case it
313 # specifies the variables to pass to the template when it is rendered),
314 # or a string, in which case it specifies the actual text of the message.
315 adv_attr_accessor :body
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
316
59f1df1b » jamis
2005-10-16 Update/extend ActionMailer documentation (rdoc)
317 # Specify the CC addresses for the message.
318 adv_attr_accessor :cc
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
319
59f1df1b » jamis
2005-10-16 Update/extend ActionMailer documentation (rdoc)
320 # Specify the charset to use for the message. This defaults to the
321 # +default_charset+ specified for ActionMailer::Base.
322 adv_attr_accessor :charset
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
323
59f1df1b » jamis
2005-10-16 Update/extend ActionMailer documentation (rdoc)
324 # Specify the content type for the message. This defaults to <tt>text/plain</tt>
325 # in most cases, but can be automatically set in some situations.
326 adv_attr_accessor :content_type
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
327
59f1df1b » jamis
2005-10-16 Update/extend ActionMailer documentation (rdoc)
328 # Specify the from address for the message.
329 adv_attr_accessor :from
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
330
cf6299db » Adam
2008-05-23 Add ActionMailer#reply_to. [#245 state:resolved]
331 # Specify the address (if different than the "from" address) to direct
332 # replies to this message.
333 adv_attr_accessor :reply_to
334
59f1df1b » jamis
2005-10-16 Update/extend ActionMailer documentation (rdoc)
335 # Specify additional headers to be added to the message.
336 adv_attr_accessor :headers
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
337
59f1df1b » jamis
2005-10-16 Update/extend ActionMailer documentation (rdoc)
338 # Specify the order in which parts should be sorted, based on content-type.
339 # This defaults to the value for the +default_implicit_parts_order+.
340 adv_attr_accessor :implicit_parts_order
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
341
59f1df1b » jamis
2005-10-16 Update/extend ActionMailer documentation (rdoc)
342 # Defaults to "1.0", but may be explicitly given if needed.
343 adv_attr_accessor :mime_version
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
344
59f1df1b » jamis
2005-10-16 Update/extend ActionMailer documentation (rdoc)
345 # The recipient addresses for the message, either as a string (for a single
346 # address) or an array (for multiple addresses).
347 adv_attr_accessor :recipients
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
348
59f1df1b » jamis
2005-10-16 Update/extend ActionMailer documentation (rdoc)
349 # The date on which the message was sent. If not set (the default), the
350 # header will be set by the delivery agent.
351 adv_attr_accessor :sent_on
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
352
59f1df1b » jamis
2005-10-16 Update/extend ActionMailer documentation (rdoc)
353 # Specify the subject of the message.
354 adv_attr_accessor :subject
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
355
59f1df1b » jamis
2005-10-16 Update/extend ActionMailer documentation (rdoc)
356 # Specify the template name to use for current message. This is the "base"
357 # template name, without the extension or directory, and may be used to
358 # have multiple mailer methods share the same template.
359 adv_attr_accessor :template
165097ed » dhh
2004-12-07 Added access to custom headers, like cc, bcc, and reply-to #268 [Andr…
360
bd5ed651 » technoweenie
2007-11-26 Update ActionMailer so it treats ActionView the same way that ActionC…
361 # Override the mailer name, which defaults to an inflected version of the
362 # mailer's class name. If you want to use a template in a non-standard
363 # location, you can use this to specify that location.
364 def mailer_name(value = nil)
365 if value
366 self.mailer_name = value
367 else
368 self.class.mailer_name
369 end
370 end
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
371
bd5ed651 » technoweenie
2007-11-26 Update ActionMailer so it treats ActionView the same way that ActionC…
372 def mailer_name=(value)
373 self.class.mailer_name = value
374 end
375
59f1df1b » jamis
2005-10-16 Update/extend ActionMailer documentation (rdoc)
376 # The mail object instance referenced by this mailer.
377 attr_reader :mail
6228220c » dhh
2008-09-09 Revert "Revert "Add layout functionality to mailers.""
378 attr_reader :template_name, :default_template_name, :action_name
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
379
eb9af20b » wycats
2009-01-22 Begin unifying the interface between ActionController and ActionView
380 def controller_path
381 self.class.controller_path
382 end
383
384 def formats
385 @template.formats
386 end
387
eda17194 » jamis
2005-07-31 ActionMailer::Base.deliver(email) had been accidentally removed, but …
388 class << self
bd5ed651 » technoweenie
2007-11-26 Update ActionMailer so it treats ActionView the same way that ActionC…
389 attr_writer :mailer_name
390
391 def mailer_name
392 @mailer_name ||= name.underscore
393 end
394
395 # for ActionView compatibility
396 alias_method :controller_name, :mailer_name
397 alias_method :controller_path, :mailer_name
398
3cf773b1 » floehopper
2008-08-29 ActionMailer should respond_to? to methods handled by method_missing [#…
399 def respond_to?(method_symbol, include_private = false) #:nodoc:
400 matches_dynamic_method?(method_symbol) || super
401 end
402
403 def method_missing(method_symbol, *parameters) #:nodoc:
a62e9e90 » mocoso
2008-11-11 Fix for ActionMailer::Base.method_missing so that it raises NoMethodE…
404 if match = matches_dynamic_method?(method_symbol)
405 case match[1]
406 when 'create' then new(match[2], *parameters).mail
407 when 'deliver' then new(match[2], *parameters).deliver!
408 when 'new' then nil
c65075fe » mocoso
2008-11-11 Fixed method_missing for ActionMailer so it no longer matches methods…
409 else super
a62e9e90 » mocoso
2008-11-11 Fix for ActionMailer::Base.method_missing so that it raises NoMethodE…
410 end
411 else
412 super
eda17194 » jamis
2005-07-31 ActionMailer::Base.deliver(email) had been accidentally removed, but …
413 end
414 end
415
59f1df1b » jamis
2005-10-16 Update/extend ActionMailer documentation (rdoc)
416 # Receives a raw email, parses it into an email object, decodes it,
417 # instantiates a new mailer, and passes the email object to the mailer
98dc5827 » lifo
2008-05-25 Merge docrails.
418 # object's +receive+ method. If you want your mailer to be able to
419 # process incoming messages, you'll need to implement a +receive+
59f1df1b » jamis
2005-10-16 Update/extend ActionMailer documentation (rdoc)
420 # method that accepts the email object as a parameter:
421 #
422 # class MyMailer < ActionMailer::Base
423 # def receive(mail)
424 # ...
425 # end
426 # end
427 def receive(raw_email)
eda17194 » jamis
2005-07-31 ActionMailer::Base.deliver(email) had been accidentally removed, but …
428 logger.info "Received mail:\n #{raw_email}" unless logger.nil?
429 mail = TMail::Mail.parse(raw_email)
430 mail.base64_decode
431 new.receive(mail)
432 end
433
434 # Deliver the given mail object directly. This can be used to deliver
435 # a preconstructed mail object, like:
436 #
437 # email = MyMailer.create_some_mail(parameters)
438 # email.set_some_obscure_header "frobnicate"
439 # MyMailer.deliver(email)
440 def deliver(mail)
441 new.deliver!(mail)
442 end
271404e8 » jeremy
2007-06-07 Register alternative template engines using ActionMailer::Base.regist…
443
cb21db1a » josh
2008-07-31 Treat ActionMailer template_root as a view path set internally to avo…
444 def template_root
445 self.view_paths && self.view_paths.first
446 end
447
61c90a4a » NZKoz
2008-01-21 Reapply the TemplateFinder first applied in [8669] then reverted in […
448 def template_root=(root)
cb21db1a » josh
2008-07-31 Treat ActionMailer template_root as a view path set internally to avo…
449 self.view_paths = ActionView::Base.process_view_paths(root)
61c90a4a » NZKoz
2008-01-21 Reapply the TemplateFinder first applied in [8669] then reverted in […
450 end
3cf773b1 » floehopper
2008-08-29 ActionMailer should respond_to? to methods handled by method_missing [#…
451
452 private
453 def matches_dynamic_method?(method_name) #:nodoc:
454 method_name = method_name.to_s
c65075fe » mocoso
2008-11-11 Fixed method_missing for ActionMailer so it no longer matches methods…
455 /^(create|deliver)_([_a-z]\w*)/.match(method_name) || /^(new)$/.match(method_name)
3cf773b1 » floehopper
2008-08-29 ActionMailer should respond_to? to methods handled by method_missing [#…
456 end
eda17194 » jamis
2005-07-31 ActionMailer::Base.deliver(email) had been accidentally removed, but …
457 end
458
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
459 # Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer
460 # will be initialized according to the named method. If not, the mailer will
461 # remain uninitialized (useful when you only need to invoke the "receive"
462 # method, for instance).
2789b5d2 » dhh
2005-07-06 Tuned documentation for release (AM)
463 def initialize(method_name=nil, *parameters) #:nodoc:
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
464 create!(method_name, *parameters) if method_name
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
465 end
466
467 # Initialize the mailer via the given +method_name+. The body will be
468 # rendered and a new TMail::Mail object created.
2789b5d2 » dhh
2005-07-06 Tuned documentation for release (AM)
469 def create!(method_name, *parameters) #:nodoc:
f474f337 » jamis
2005-08-22 Move mailer initialization to a separate (overridable) method, so tha…
470 initialize_defaults(method_name)
c3ff04b0 » jeremy
2006-11-13 Allow mailer actions named send by using __send__ internally. Closes #…
471 __send__(method_name, *parameters)
0a132c2f » Yehuda Katz + Carl Lerche
2009-04-22 Refactor ActionView::Path
472
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
473 # If an explicit, textual body has not been set, we check assumptions.
474 unless String === @body
475 # First, we look to see if there are any likely templates that match,
476 # which include the content-type in their file name (i.e.,
21187c0f » dhh
2007-02-21 Apply the rest of Chads patch
477 # "the_template_file.text.html.erb", etc.). Only do this if parts
dca4d4e8 » jamis
2005-08-22 Multipart messages specify a MIME-Version header automatically #2003
478 # have not already been specified manually.
0a132c2f » Yehuda Katz + Carl Lerche
2009-04-22 Refactor ActionView::Path
479 # if @parts.empty?
480 template_root.find_all_by_parts(@template, {}, template_path).each do |template|
b2504f8b » josh
2008-08-06 Tidy up ActionMailer rendering logic to take advantage of view path c…
481 @parts << Part.new(
ab83db9d » Yehuda Katz + Carl Lerche
2009-04-27 Fixes ActionMailer to work with the ActionView refactoring
482 :content_type => template.mime_type ? template.mime_type.to_s : "text/plain",
b2504f8b » josh
2008-08-06 Tidy up ActionMailer rendering logic to take advantage of view path c…
483 :disposition => "inline",
484 :charset => charset,
eb9af20b » wycats
2009-01-22 Begin unifying the interface between ActionController and ActionView
485 :body => render_template(template, @body)
b2504f8b » josh
2008-08-06 Tidy up ActionMailer rendering logic to take advantage of view path c…
486 )
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
487 end
0a132c2f » Yehuda Katz + Carl Lerche
2009-04-22 Refactor ActionView::Path
488
489 if @parts.size > 1
1dff1068 » sdague
2009-03-10 Allow custom type for multipart emails [#1691 state:resolved]
490 @content_type = "multipart/alternative" if @content_type !~ /^multipart/
5c981528 » jamis
2005-07-01 Better multipart support with implicit multipart/alternative and sort…
491 @parts = sort_parts(@parts, @implicit_parts_order)
492 end
0a132c2f » Yehuda Katz + Carl Lerche
2009-04-22 Refactor ActionView::Path
493 # end
494
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
495 # Then, if there were such templates, we check to see if we ought to
496 # also render a "normal" template (without the content type). If a
497 # normal template exists (or if there were no implicit parts) we render
498 # it.
0a132c2f » Yehuda Katz + Carl Lerche
2009-04-22 Refactor ActionView::Path
499 # ====
500 # TODO: Revisit this
501 # template_exists = @parts.empty?
502 # template_exists ||= template_root.find_by_parts("#{mailer_name}/#{@template}")
503 # @body = render_message(@template, @body) if template_exists
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
504
505 # Finally, if there are other message parts and a textual body exists,
506 # we shift it onto the front of the parts and set the body to nil (so
507 # that create_mail doesn't try to render it in addition to the parts).
0a132c2f » Yehuda Katz + Carl Lerche
2009-04-22 Refactor ActionView::Path
508 # ====
509 # TODO: Revisit this
510 # if !@parts.empty? && String === @body
511 # @parts.unshift Part.new(:charset => charset, :body => @body)
512 # @body = nil
513 # end
db045dbb » dhh
2004-11-24 Initial
514 end
515
dca4d4e8 » jamis
2005-08-22 Multipart messages specify a MIME-Version header automatically #2003
516 # If this is a multipart e-mail add the mime_version if it is not
517 # already set.
518 @mime_version ||= "1.0" if !@parts.empty?
519
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
520 # build the mail object itself
521 @mail = create_mail
522 end
db045dbb » dhh
2004-11-24 Initial
523
eda17194 » jamis
2005-07-31 ActionMailer::Base.deliver(email) had been accidentally removed, but …
524 # Delivers a TMail::Mail object. By default, it delivers the cached mail
98dc5827 » lifo
2008-05-25 Merge docrails.
525 # 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 …
526 # no alternate has been given as the parameter, this will fail.
59f1df1b » jamis
2005-10-16 Update/extend ActionMailer documentation (rdoc)
527 def deliver!(mail = @mail)
eda17194 » jamis
2005-07-31 ActionMailer::Base.deliver(email) had been accidentally removed, but …
528 raise "no mail object available for delivery!" unless mail
eb9af20b » wycats
2009-01-22 Begin unifying the interface between ActionController and ActionView
529
fbd3eb71 » jeremy
2008-02-02 Less verbose mail logging: just recipients for :info log level; the w…
530 unless logger.nil?
be364551 » jeremy
2008-03-31 Ruby 1.9 compat: use Array() instead of #to_a.
531 logger.info "Sent mail to #{Array(recipients).join(', ')}"
fbd3eb71 » jeremy
2008-02-02 Less verbose mail logging: just recipients for :info log level; the w…
532 logger.debug "\n#{mail.encoded}"
533 end
256e800a » dhh
2005-04-11 Fixed quoting for all address headers, not just to #955 [Jamis Buck] …
534
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
535 begin
c3ff04b0 » jeremy
2006-11-13 Allow mailer actions named send by using __send__ internally. Closes #…
536 __send__("perform_delivery_#{delivery_method}", mail) if perform_deliveries
12ff554c » jeremy
2006-08-31 Tighten rescue clauses. Closes #5985.
537 rescue Exception => e # Net::SMTP errors or sendmail pipe errors
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
538 raise e if raise_delivery_errors
539 end
3fad0cd0 » dhh
2005-02-19 Added support for charsets for both subject and body. The default cha…
540
eda17194 » jamis
2005-07-31 ActionMailer::Base.deliver(email) had been accidentally removed, but …
541 return mail
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
542 end
3fad0cd0 » dhh
2005-02-19 Added support for charsets for both subject and body. The default cha…
543
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
544 private
f474f337 » jamis
2005-08-22 Move mailer initialization to a separate (overridable) method, so tha…
545 # Set up the default values for the various instance variables of this
546 # mailer. Subclasses may override this method to provide different
547 # defaults.
548 def initialize_defaults(method_name)
95e8740f » dhh
2005-10-26 Allow Mailers to have custom initialize methods that set default inst…
549 @charset ||= @@default_charset.dup
550 @content_type ||= @@default_content_type.dup
551 @implicit_parts_order ||= @@default_implicit_parts_order.dup
552 @template ||= method_name
6228220c » dhh
2008-09-09 Revert "Revert "Add layout functionality to mailers.""
553 @default_template_name = @action_name = @template
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
554 @mailer_name ||= self.class.name.underscore
95e8740f » dhh
2005-10-26 Allow Mailers to have custom initialize methods that set default inst…
555 @parts ||= []
556 @headers ||= {}
557 @body ||= {}
dca4d4e8 » jamis
2005-08-22 Multipart messages specify a MIME-Version header automatically #2003
558 @mime_version = @@default_mime_version.dup if @@default_mime_version
f474f337 » jamis
2005-08-22 Move mailer initialization to a separate (overridable) method, so tha…
559 end
560
eb9af20b » wycats
2009-01-22 Begin unifying the interface between ActionController and ActionView
561 def render_template(template, body)
ab83db9d » Yehuda Katz + Carl Lerche
2009-04-27 Fixes ActionMailer to work with the ActionView refactoring
562 if template.respond_to?(:mime_type)
563 @current_template_content_type = template.mime_type && template.mime_type.to_sym.to_s
1d4554d7 » Colin Curtin
2008-11-20 ActionMailer should respect content type when choosing layouts
564 end
eb9af20b » wycats
2009-01-22 Begin unifying the interface between ActionController and ActionView
565
566 @template = initialize_template_class(body)
ab83db9d » Yehuda Katz + Carl Lerche
2009-04-27 Fixes ActionMailer to work with the ActionView refactoring
567 layout = _pick_layout(layout, true) unless
568 ActionController::Base.exempt_from_layout.include?(template.handler)
eb9af20b » wycats
2009-01-22 Begin unifying the interface between ActionController and ActionView
569 @template._render_template_with_layout(template, layout, {})
570 ensure
571 @current_template_content_type = nil
572 end
573
574 def render_message(method_name, body)
74612273 » josh
2008-07-19 Ruby 1.9: Call join on template_root instead of to_s
575 render :file => method_name, :body => body
1d4554d7 » Colin Curtin
2008-11-20 ActionMailer should respect content type when choosing layouts
576 ensure
577 @current_template_content_type = nil
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
578 end
ae1e8520 » jamis
2005-08-22 Add a unified render method to ActionMailer (delegates to ActionView:…
579
580 def render(opts)
eb9af20b » wycats
2009-01-22 Begin unifying the interface between ActionController and ActionView
581 layout, file = opts.delete(:layout), opts[:file]
582
6228220c » dhh
2008-09-09 Revert "Revert "Add layout functionality to mailers.""
583 begin
eb9af20b » wycats
2009-01-22 Begin unifying the interface between ActionController and ActionView
584 @template = initialize_template_class(opts.delete(:body))
585
586 if file
587 prefix = mailer_name unless file =~ /\//
0a132c2f » Yehuda Katz + Carl Lerche
2009-04-22 Refactor ActionView::Path
588 template = view_paths.find_by_parts(file, {:formats => formats}, prefix)
eb9af20b » wycats
2009-01-22 Begin unifying the interface between ActionController and ActionView
589 end
590
591 layout = _pick_layout(layout,
ab83db9d » Yehuda Katz + Carl Lerche
2009-04-27 Fixes ActionMailer to work with the ActionView refactoring
592 !template || ActionController::Base.exempt_from_layout.include?(template.handler))
eb9af20b » wycats
2009-01-22 Begin unifying the interface between ActionController and ActionView
593
594 if template
595 @template._render_template_with_layout(template, layout, opts)
596 elsif inline = opts[:inline]
597 @template._render_inline(inline, layout, opts)
598 end
6228220c » dhh
2008-09-09 Revert "Revert "Add layout functionality to mailers.""
599 end
600 end
601
602 def default_template_format
1d4554d7 » Colin Curtin
2008-11-20 ActionMailer should respect content type when choosing layouts
603 if @current_template_content_type
604 Mime::Type.lookup(@current_template_content_type).to_sym
605 else
606 :html
607 end
6228220c » dhh
2008-09-09 Revert "Revert "Add layout functionality to mailers.""
608 end
609
cb21db1a » josh
2008-07-31 Treat ActionMailer template_root as a view path set internally to avo…
610 def template_root
611 self.class.template_root
612 end
613
614 def template_root=(root)
615 self.class.template_root = root
616 end
617
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
618 def template_path
0a132c2f » Yehuda Katz + Carl Lerche
2009-04-22 Refactor ActionView::Path
619 "#{mailer_name}"
db045dbb » dhh
2004-11-24 Initial
620 end
621
5ec990af » jamis
2005-06-16 Helper support for ActionMailer
622 def initialize_template_class(assigns)
441e4e22 » svenfuchs
2009-02-22 load plugin view_paths to action_mailer view_paths and make action_ma…
623 template = ActionView::Base.new(self.class.view_paths, assigns, self)
eb9af20b » wycats
2009-01-22 Begin unifying the interface between ActionController and ActionView
624 template.formats = [default_template_format]
1d4554d7 » Colin Curtin
2008-11-20 ActionMailer should respect content type when choosing layouts
625 template
5ec990af » jamis
2005-06-16 Helper support for ActionMailer
626 end
627
5c981528 » jamis
2005-07-01 Better multipart support with implicit multipart/alternative and sort…
628 def sort_parts(parts, order = [])
629 order = order.collect { |s| s.downcase }
0a132c2f » Yehuda Katz + Carl Lerche
2009-04-22 Refactor ActionView::Path
630
5c981528 » jamis
2005-07-01 Better multipart support with implicit multipart/alternative and sort…
631 parts = parts.sort do |a, b|
632 a_ct = a.content_type.downcase
633 b_ct = b.content_type.downcase
634
635 a_in = order.include? a_ct
636 b_in = order.include? b_ct
637
638 s = case
639 when a_in && b_in
640 order.index(a_ct) <=> order.index(b_ct)
641 when a_in
642 -1
643 when b_in
644 1
645 else
646 a_ct <=> b_ct
647 end
648
649 # reverse the ordering because parts that come last are displayed
650 # first in mail clients
651 (s * -1)
652 end
653
654 parts
655 end
656
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
657 def create_mail
658 m = TMail::Mail.new
74a612c4 » dhh
2005-05-02 Added that delivery errors are caught in a way so the mail is still r…
659
cf6299db » Adam
2008-05-23 Add ActionMailer#reply_to. [#245 state:resolved]
660 m.subject, = quote_any_if_necessary(charset, subject)
661 m.to, m.from = quote_any_address_if_necessary(charset, recipients, from)
662 m.bcc = quote_address_if_necessary(bcc, charset) unless bcc.nil?
663 m.cc = quote_address_if_necessary(cc, charset) unless cc.nil?
664 m.reply_to = quote_address_if_necessary(reply_to, charset) unless reply_to.nil?
dca4d4e8 » jamis
2005-08-22 Multipart messages specify a MIME-Version header automatically #2003
665 m.mime_version = mime_version unless mime_version.nil?
cf6299db » Adam
2008-05-23 Add ActionMailer#reply_to. [#245 state:resolved]
666 m.date = sent_on.to_time rescue sent_on if sent_on
667
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
668 headers.each { |k, v| m[k] = v }
db045dbb » dhh
2004-11-24 Initial
669
db0e8ff1 » jamis
2006-03-18 Parse content-type apart before using it so that sub-parts of the hea…
670 real_content_type, ctype_attrs = parse_content_type
0a132c2f » Yehuda Katz + Carl Lerche
2009-04-22 Refactor ActionView::Path
671
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
672 if @parts.empty?
db0e8ff1 » jamis
2006-03-18 Parse content-type apart before using it so that sub-parts of the hea…
673 m.set_content_type(real_content_type, nil, ctype_attrs)
e201fc75 » josh
2008-11-23 use autoload instead of explicit requires for ActionMailer
674 m.body = normalize_new_lines(body)
0a132c2f » Yehuda Katz + Carl Lerche
2009-04-22 Refactor ActionView::Path
675 elsif @parts.size == 1 && @parts.first.parts.empty?
676 m.set_content_type(real_content_type, nil, ctype_attrs)
677 m.body = normalize_new_lines(@parts.first.body)
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
678 else
679 if String === body
680 part = TMail::Mail.new
e201fc75 » josh
2008-11-23 use autoload instead of explicit requires for ActionMailer
681 part.body = normalize_new_lines(body)
db0e8ff1 » jamis
2006-03-18 Parse content-type apart before using it so that sub-parts of the hea…
682 part.set_content_type(real_content_type, nil, ctype_attrs)
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
683 part.set_content_disposition "inline"
684 m.parts << part
685 end
3fad0cd0 » dhh
2005-02-19 Added support for charsets for both subject and body. The default cha…
686
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
687 @parts.each do |p|
688 part = (TMail::Mail === p ? p : p.to_mail(self))
689 m.parts << part
690 end
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
691
49efa02b » jamis
2006-03-19 Nil charset caused subject line to be improperly quoted in implicitly…
692 if real_content_type =~ /multipart/
693 ctype_attrs.delete "charset"
694 m.set_content_type(real_content_type, nil, ctype_attrs)
695 end
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
696 end
256e800a » dhh
2005-04-11 Fixed quoting for all address headers, not just to #955 [Jamis Buck] …
697
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
698 @mail = m
256e800a » dhh
2005-04-11 Fixed quoting for all address headers, not just to #955 [Jamis Buck] …
699 end
700
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
701 def perform_delivery_smtp(mail)
508c26c0 » jamis
2005-06-06 BCC headers are removed when sending via SMTP
702 destinations = mail.destinations
703 mail.ready_to_send
1d57ccbc » Friedrich Göpel
2009-06-09 1.9 compatibility - don't pass an array as the from address as this e…
704 sender = (mail['return-path'] && mail['return-path'].spec) || mail['from']
508c26c0 » jamis
2005-06-06 BCC headers are removed when sending via SMTP
705
732c724d » granth
2008-11-05 Turn on STARTTLS if it is available in Net::SMTP (added in Ruby 1.8.7…
706 smtp = Net::SMTP.new(smtp_settings[:address], smtp_settings[:port])
c2e7851f » josevalim
2009-01-11 Add ActionMailer::Base#enable_starttls_auto option for enabling/disab…
707 smtp.enable_starttls_auto if smtp_settings[:enable_starttls_auto] && smtp.respond_to?(:enable_starttls_auto)
732c724d » granth
2008-11-05 Turn on STARTTLS if it is available in Net::SMTP (added in Ruby 1.8.7…
708 smtp.start(smtp_settings[:domain], smtp_settings[:user_name], smtp_settings[:password],
709 smtp_settings[:authentication]) do |smtp|
5c0d38f6 » dhh
2008-03-27 Fixed that a return-path header would be ignored (closes #7572) [joost]
710 smtp.sendmail(mail.encoded, sender, destinations)
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
711 end
256e800a » dhh
2005-04-11 Fixed quoting for all address headers, not just to #955 [Jamis Buck] …
712 end
713
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
714 def perform_delivery_sendmail(mail)
77730f7c » NZKoz
2008-04-05 Avoid modifying the sendmail_settings hash when using the return path…
715 sendmail_args = sendmail_settings[:arguments]
716 sendmail_args += " -f \"#{mail['return-path']}\"" if mail['return-path']
717 IO.popen("#{sendmail_settings[:location]} #{sendmail_args}","w+") do |sm|
bb62568c » dhh
2005-07-17 Fix problem with sendmail delivery where headers should be delimited …
718 sm.print(mail.encoded.gsub(/\r/, ''))
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
719 sm.flush
256e800a » dhh
2005-04-11 Fixed quoting for all address headers, not just to #955 [Jamis Buck] …
720 end
721 end
722
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
723 def perform_delivery_test(mail)
724 deliveries << mail
725 end
db045dbb » dhh
2004-11-24 Initial
726 end
e201fc75 » josh
2008-11-23 use autoload instead of explicit requires for ActionMailer
727
728 Base.class_eval do
729 include Helpers
730 helper MailHelper
731 end
db045dbb » dhh
2004-11-24 Initial
732 end
Something went wrong with that request. Please try again.