Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 714 lines (626 sloc) 28.631 kb
a63caa4 Get tests to run (with failures) without old base around
Yehuda Katz + Carl Lerche authored
1 require "active_support/core_ext/class"
5314abe Keep ActionMailer using the old layouts code until it gets refactored.
Yehuda Katz + Carl Lerche authored
2 # Use the old layouts until actionmailer gets refactored
19c3495 rm -r controller/base!
Yehuda Katz + Carl Lerche authored
3 require "action_controller/legacy/layout"
a63caa4 Get tests to run (with failures) without old base around
Yehuda Katz + Carl Lerche authored
4
c4590d5 @dhh Fixed docs
dhh authored
5 module ActionMailer #:nodoc:
98dc582 @lifo Merge docrails.
lifo authored
6 # Action Mailer allows you to send email from your application using a mailer model and views.
db045db @dhh Initial
dhh authored
7 #
20bd4bd @dhh Updated docs and otherwise
dhh authored
8 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
9 # = Mailer Models
20bd4bd @dhh Updated docs and otherwise
dhh authored
10 #
98dc582 @lifo Merge docrails.
lifo authored
11 # 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
12 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
13 # $ script/generate mailer Notifier
14 #
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
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
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
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
c3f53f4 @lifo Merge docrails
lifo authored
24 # bcc ["bcc@example.com", "Order Watcher <watcher@example.com>"]
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
25 # from "system@example.com"
26 # subject "New account information"
20bd4bd @dhh Updated docs and otherwise
dhh authored
27 # body :account => recipient
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
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.
cf6299d Add ActionMailer#reply_to. [#245 state:resolved]
Adam authored
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.
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
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 #
5c0d38f @dhh Fixed that a return-path header would be ignored (closes #7572) [joost]
dhh authored
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 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
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 #
5c0d38f @dhh Fixed that a return-path header would be ignored (closes #7572) [joost]
dhh authored
50 # So, for example, <tt>body :account => recipient</tt> would result
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
51 # in an instance variable <tt>@account</tt> with the value of <tt>recipient</tt> being accessible in the
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
52 # view.
53 #
20bd4bd @dhh Updated docs and otherwise
dhh authored
54 #
55 # = Mailer views
56 #
98dc582 @lifo Merge docrails.
lifo authored
57 # Like Action Controller, each mailer class has a corresponding view directory
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
58 # in which each method of the class looks for a template with its name.
21187c0 @dhh Apply the rest of Chads patch
dhh authored
59 # 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
60 # in your mailer model. For example, in the mailer defined above, the template at
21187c0 @dhh Apply the rest of Chads patch
dhh authored
61 # <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
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 #
20bd4bd @dhh Updated docs and otherwise
dhh authored
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) %>
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
74 #
20bd4bd @dhh Updated docs and otherwise
dhh authored
75 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
76 # = Generating URLs
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
77 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
78 # 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
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.
20bd4bd @dhh Updated docs and otherwise
dhh authored
81 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
82 # 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
83 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
84 # <%= url_for(:host => "example.com", :controller => "welcome", :action => "greeting") %>
20bd4bd @dhh Updated docs and otherwise
dhh authored
85 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
86 # 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
87 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
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 #
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
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
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
94 # the <tt>ActionMailer::Base.default_url_options</tt> hash as follows:
95 #
96 # ActionMailer::Base.default_url_options[:host] = "example.com"
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
97 #
dc4eec1 @lifo Merge docrails:
lifo authored
98 # 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
99 #
100 # config.action_mailer.default_url_options = { :host => "example.com" }
20bd4bd @dhh Updated docs and otherwise
dhh authored
101 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
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
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
104 # 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
105 # explicitly provided.
20bd4bd @dhh Updated docs and otherwise
dhh authored
106 #
107 # = Sending mail
108 #
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
109 # 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
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)
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
115 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
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 #
20bd4bd @dhh Updated docs and otherwise
dhh authored
122 #
123 # = HTML email
124 #
21187c0 @dhh Apply the rest of Chads patch
dhh authored
125 # 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
126 # set the content type to html.
127 #
128 # class MyMailer < ActionMailer::Base
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
129 # def signup_notification(recipient)
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored
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"
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
135 # end
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
136 # end
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
137 #
20bd4bd @dhh Updated docs and otherwise
dhh authored
138 #
139 # = Multipart email
140 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
141 # You can explicitly specify multipart messages:
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
142 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
143 # class ApplicationMailer < ActionMailer::Base
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
144 # def signup_notification(recipient)
145 # recipients recipient.email_address_with_name
146 # subject "New account information"
147 # from "system@example.com"
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored
148 # content_type "multipart/alternative"
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
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
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
158 # end
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
159 #
98dc582 @lifo Merge docrails.
lifo authored
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
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
163 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
164 # For example, if the following templates existed:
21187c0 @dhh Apply the rest of Chads patch
dhh authored
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
169 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
170 # Each would be rendered and added as a separate part to the message,
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored
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
175 #
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored
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
179 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
180 # = Attachments
20bd4bd @dhh Updated docs and otherwise
dhh authored
181 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored
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
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
199 # end
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
200 # end
c927aa0 @dhh Updated documentation
dhh authored
201 #
20bd4bd @dhh Updated docs and otherwise
dhh authored
202 #
c927aa0 @dhh Updated documentation
dhh authored
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
207 # * <tt>template_root</tt> - Determines the base from which template references will be made.
c927aa0 @dhh Updated documentation
dhh authored
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
212 # * <tt>smtp_settings</tt> - Allows detailed configuration for <tt>:smtp</tt> delivery method:
dc4eec1 @lifo Merge docrails:
lifo authored
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
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
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
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
222 #
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored
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
226 #
fbe6c3c @edavis10 Adds a :file delivery_method to save email to a file on disk
edavis10 authored
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
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
231 #
fbe6c3c @edavis10 Adds a :file delivery_method to save email to a file on disk
edavis10 authored
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
233 # and <tt>:file</tt>. Or you may provide a custom delivery method object eg. MyOwnDeliveryMethodClass.new
c927aa0 @dhh Updated documentation
dhh authored
234 #
dc4eec1 @lifo Merge docrails:
lifo authored
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
236 # but this can be turned off to help functional testing.
237 #
64092de @fxn Improve documentation coverage and markup
fxn authored
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
239 # for unit and functional testing.
af56c80 @dhh Updated documentation
dhh authored
240 #
b2504f8 @josh Tidy up ActionMailer rendering logic to take advantage of view path c…
josh authored
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
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
243 #
475bd74 @dhh Fix docs (closes #2598)
dhh authored
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
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
246 #
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored
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
249 #
475bd74 @dhh Fix docs (closes #2598)
dhh authored
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
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
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
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
254 # +implicit_parts_order+.
db045db @dhh Initial
dhh authored
255 class Base
e201fc7 @josh use autoload instead of explicit requires for ActionMailer
josh authored
256 include AdvAttrAccessor, PartContainer, Quoting, Utils
09f798b @josevalim Instrument create and deliver in ActionMailer.
josevalim authored
257 extend AbstractController::RenderingController
258
6228220 @dhh Revert "Revert "Add layout functionality to mailers.""
dhh authored
259 if Object.const_defined?(:ActionController)
260 include ActionController::UrlWriter
5314abe Keep ActionMailer using the old layouts code until it gets refactored.
Yehuda Katz + Carl Lerche authored
261 include ActionController::Layout
6228220 @dhh Revert "Revert "Add layout functionality to mailers.""
dhh authored
262 end
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
263
c927aa0 @dhh Updated documentation
dhh authored
264 private_class_method :new #:nodoc:
db045db @dhh Initial
dhh authored
265
cb21db1 @josh Treat ActionMailer template_root as a view path set internally to avo…
josh authored
266 class_inheritable_accessor :view_paths
441e4e2 @svenfuchs load plugin view_paths to action_mailer view_paths and make action_ma…
svenfuchs authored
267 self.view_paths = []
268
db045db @dhh Initial
dhh authored
269 cattr_accessor :logger
270
f4f7677 @matthewrudy abstract all of the ActionMailer delivery methods into their own clas…
matthewrudy authored
271 class << self
272 delegate :settings, :settings=, :to => ActionMailer::DeliveryMethod::File, :prefix => :file
273 delegate :settings, :settings=, :to => ActionMailer::DeliveryMethod::Sendmail, :prefix => :sendmail
274 delegate :settings, :settings=, :to => ActionMailer::DeliveryMethod::Smtp, :prefix => :smtp
275
276 def delivery_method=(method_name)
277 @delivery_method = ActionMailer::DeliveryMethod.lookup_method(method_name)
278 end
279 end
280 self.delivery_method = :smtp
281 superclass_delegating_reader :delivery_method
fbe6c3c @edavis10 Adds a :file delivery_method to save email to a file on disk
edavis10 authored
282
db045db @dhh Initial
dhh authored
283 @@raise_delivery_errors = true
284 cattr_accessor :raise_delivery_errors
285
286 @@perform_deliveries = true
287 cattr_accessor :perform_deliveries
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
288
db045db @dhh Initial
dhh authored
289 @@deliveries = []
290 cattr_accessor :deliveries
291
3fad0cd @dhh Added support for charsets for both subject and body. The default cha…
dhh authored
292 @@default_charset = "utf-8"
293 cattr_accessor :default_charset
294
100fd72 @jamis Added a "content_type" accessor to allow messages to explicitly speci…
jamis authored
295 @@default_content_type = "text/plain"
296 cattr_accessor :default_content_type
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
297
45b5555 @jamis Make mime version default to 1.0. closes #2323
jamis authored
298 @@default_mime_version = "1.0"
dca4d4e @jamis Multipart messages specify a MIME-Version header automatically #2003 …
jamis authored
299 cattr_accessor :default_mime_version
100fd72 @jamis Added a "content_type" accessor to allow messages to explicitly speci…
jamis authored
300
5c98152 @jamis Better multipart support with implicit multipart/alternative and sort…
jamis authored
301 @@default_implicit_parts_order = [ "text/html", "text/enriched", "text/plain" ]
302 cattr_accessor :default_implicit_parts_order
303
28bf2fa @josh Protect body ivar from being clobbered by the mailer template assigns
josh authored
304 cattr_reader :protected_instance_variables
305 @@protected_instance_variables = %w(@body)
306
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
307 # Specify the BCC addresses for the message
308 adv_attr_accessor :bcc
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
309
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
310 # Define the body of the message. This is either a Hash (in which case it
311 # specifies the variables to pass to the template when it is rendered),
312 # or a string, in which case it specifies the actual text of the message.
313 adv_attr_accessor :body
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
314
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
315 # Specify the CC addresses for the message.
316 adv_attr_accessor :cc
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
317
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
318 # Specify the charset to use for the message. This defaults to the
319 # +default_charset+ specified for ActionMailer::Base.
320 adv_attr_accessor :charset
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
321
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
322 # Specify the content type for the message. This defaults to <tt>text/plain</tt>
323 # in most cases, but can be automatically set in some situations.
324 adv_attr_accessor :content_type
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
325
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
326 # Specify the from address for the message.
327 adv_attr_accessor :from
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
328
cf6299d Add ActionMailer#reply_to. [#245 state:resolved]
Adam authored
329 # Specify the address (if different than the "from" address) to direct
330 # replies to this message.
331 adv_attr_accessor :reply_to
332
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
333 # Specify additional headers to be added to the message.
334 adv_attr_accessor :headers
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
335
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
336 # Specify the order in which parts should be sorted, based on content-type.
337 # This defaults to the value for the +default_implicit_parts_order+.
338 adv_attr_accessor :implicit_parts_order
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
339
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
340 # Defaults to "1.0", but may be explicitly given if needed.
341 adv_attr_accessor :mime_version
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
342
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
343 # The recipient addresses for the message, either as a string (for a single
344 # address) or an array (for multiple addresses).
345 adv_attr_accessor :recipients
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
346
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
347 # The date on which the message was sent. If not set (the default), the
348 # header will be set by the delivery agent.
349 adv_attr_accessor :sent_on
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
350
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
351 # Specify the subject of the message.
352 adv_attr_accessor :subject
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
353
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
354 # Specify the template name to use for current message. This is the "base"
355 # template name, without the extension or directory, and may be used to
356 # have multiple mailer methods share the same template.
357 adv_attr_accessor :template
165097e @dhh Added access to custom headers, like cc, bcc, and reply-to #268 [Andr…
dhh authored
358
bd5ed65 @technoweenie Update ActionMailer so it treats ActionView the same way that ActionC…
technoweenie authored
359 # Override the mailer name, which defaults to an inflected version of the
360 # mailer's class name. If you want to use a template in a non-standard
361 # location, you can use this to specify that location.
362 def mailer_name(value = nil)
363 if value
364 self.mailer_name = value
365 else
366 self.class.mailer_name
367 end
368 end
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
369
bd5ed65 @technoweenie Update ActionMailer so it treats ActionView the same way that ActionC…
technoweenie authored
370 def mailer_name=(value)
371 self.class.mailer_name = value
372 end
373
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
374 # The mail object instance referenced by this mailer.
375 attr_reader :mail
6228220 @dhh Revert "Revert "Add layout functionality to mailers.""
dhh authored
376 attr_reader :template_name, :default_template_name, :action_name
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
377
eb9af20 @wycats Begin unifying the interface between ActionController and ActionView
wycats authored
378 def controller_path
379 self.class.controller_path
380 end
8b340ab @josevalim Revert "Rename Orchestra to Notifications [#3321 state:resolved]"
josevalim authored
381
eb9af20 @wycats Begin unifying the interface between ActionController and ActionView
wycats authored
382 def formats
383 @template.formats
384 end
385
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but …
jamis authored
386 class << self
bd5ed65 @technoweenie Update ActionMailer so it treats ActionView the same way that ActionC…
technoweenie authored
387 attr_writer :mailer_name
388
389 def mailer_name
390 @mailer_name ||= name.underscore
391 end
392
393 # for ActionView compatibility
394 alias_method :controller_name, :mailer_name
395 alias_method :controller_path, :mailer_name
396
3cf773b @floehopper ActionMailer should respond_to? to methods handled by method_missing …
floehopper authored
397 def respond_to?(method_symbol, include_private = false) #:nodoc:
398 matches_dynamic_method?(method_symbol) || super
399 end
400
401 def method_missing(method_symbol, *parameters) #:nodoc:
a62e9e9 @mocoso Fix for ActionMailer::Base.method_missing so that it raises NoMethodE…
mocoso authored
402 if match = matches_dynamic_method?(method_symbol)
403 case match[1]
404 when 'create' then new(match[2], *parameters).mail
405 when 'deliver' then new(match[2], *parameters).deliver!
406 when 'new' then nil
c65075f @mocoso Fixed method_missing for ActionMailer so it no longer matches methods…
mocoso authored
407 else super
a62e9e9 @mocoso Fix for ActionMailer::Base.method_missing so that it raises NoMethodE…
mocoso authored
408 end
409 else
410 super
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but …
jamis authored
411 end
412 end
413
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
414 # Receives a raw email, parses it into an email object, decodes it,
415 # instantiates a new mailer, and passes the email object to the mailer
98dc582 @lifo Merge docrails.
lifo authored
416 # object's +receive+ method. If you want your mailer to be able to
417 # process incoming messages, you'll need to implement a +receive+
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
418 # method that accepts the email object as a parameter:
419 #
420 # class MyMailer < ActionMailer::Base
421 # def receive(mail)
422 # ...
423 # end
424 # end
425 def receive(raw_email)
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but …
jamis authored
426 logger.info "Received mail:\n #{raw_email}" unless logger.nil?
427 mail = TMail::Mail.parse(raw_email)
428 mail.base64_decode
429 new.receive(mail)
430 end
431
432 # Deliver the given mail object directly. This can be used to deliver
433 # a preconstructed mail object, like:
434 #
435 # email = MyMailer.create_some_mail(parameters)
436 # email.set_some_obscure_header "frobnicate"
437 # MyMailer.deliver(email)
438 def deliver(mail)
439 new.deliver!(mail)
440 end
271404e @jeremy Register alternative template engines using ActionMailer::Base.regist…
jeremy authored
441
cb21db1 @josh Treat ActionMailer template_root as a view path set internally to avo…
josh authored
442 def template_root
443 self.view_paths && self.view_paths.first
444 end
445
61c90a4 @NZKoz Reapply the TemplateFinder first applied in [8669] then reverted in […
NZKoz authored
446 def template_root=(root)
cb21db1 @josh Treat ActionMailer template_root as a view path set internally to avo…
josh authored
447 self.view_paths = ActionView::Base.process_view_paths(root)
61c90a4 @NZKoz Reapply the TemplateFinder first applied in [8669] then reverted in […
NZKoz authored
448 end
3cf773b @floehopper ActionMailer should respond_to? to methods handled by method_missing …
floehopper authored
449
450 private
451 def matches_dynamic_method?(method_name) #:nodoc:
452 method_name = method_name.to_s
c65075f @mocoso Fixed method_missing for ActionMailer so it no longer matches methods…
mocoso authored
453 /^(create|deliver)_([_a-z]\w*)/.match(method_name) || /^(new)$/.match(method_name)
3cf773b @floehopper ActionMailer should respond_to? to methods handled by method_missing …
floehopper authored
454 end
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but …
jamis authored
455 end
456
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
457 # Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer
458 # will be initialized according to the named method. If not, the mailer will
459 # remain uninitialized (useful when you only need to invoke the "receive"
460 # method, for instance).
2789b5d @dhh Tuned documentation for release (AM)
dhh authored
461 def initialize(method_name=nil, *parameters) #:nodoc:
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
462 create!(method_name, *parameters) if method_name
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
463 end
464
465 # Initialize the mailer via the given +method_name+. The body will be
466 # rendered and a new TMail::Mail object created.
2789b5d @dhh Tuned documentation for release (AM)
dhh authored
467 def create!(method_name, *parameters) #:nodoc:
2d7abe2 @josevalim Renamed Orchestra to Notifications once again [#3321 state:resolved]
josevalim authored
468 ActiveSupport::Notifications.instrument(:create_mail, :name => method_name) do
09f798b @josevalim Instrument create and deliver in ActionMailer.
josevalim authored
469 initialize_defaults(method_name)
470 __send__(method_name, *parameters)
471
472 # If an explicit, textual body has not been set, we check assumptions.
473 unless String === @body
474 # First, we look to see if there are any likely templates that match,
475 # which include the content-type in their file name (i.e.,
476 # "the_template_file.text.html.erb", etc.). Only do this if parts
477 # have not already been specified manually.
478 # if @parts.empty?
479 template_root.find_all(@template, {}, template_path).each do |template|
480 @parts << Part.new(
481 :content_type => template.mime_type ? template.mime_type.to_s : "text/plain",
482 :disposition => "inline",
483 :charset => charset,
484 :body => render_template(template, @body)
485 )
486 end
487
488 if @parts.size > 1
489 @content_type = "multipart/alternative" if @content_type !~ /^multipart/
490 @parts = sort_parts(@parts, @implicit_parts_order)
491 end
492 # end
493
494 # Then, if there were such templates, we check to see if we ought to
495 # also render a "normal" template (without the content type). If a
496 # normal template exists (or if there were no implicit parts) we render
497 # it.
498 # ====
499 # TODO: Revisit this
500 # template_exists = @parts.empty?
501 # template_exists ||= template_root.find("#{mailer_name}/#{@template}")
502 # @body = render_message(@template, @body) if template_exists
503
504 # Finally, if there are other message parts and a textual body exists,
505 # we shift it onto the front of the parts and set the body to nil (so
506 # that create_mail doesn't try to render it in addition to the parts).
507 # ====
508 # TODO: Revisit this
509 # if !@parts.empty? && String === @body
510 # @parts.unshift Part.new(:charset => charset, :body => @body)
511 # @body = nil
512 # end
513 end
db045db @dhh Initial
dhh authored
514
09f798b @josevalim Instrument create and deliver in ActionMailer.
josevalim authored
515 # If this is a multipart e-mail add the mime_version if it is not
516 # already set.
517 @mime_version ||= "1.0" if !@parts.empty?
dca4d4e @jamis Multipart messages specify a MIME-Version header automatically #2003 …
jamis authored
518
09f798b @josevalim Instrument create and deliver in ActionMailer.
josevalim authored
519 # build the mail object itself
520 @mail = create_mail
521 end
522
523 @mail
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
524 end
db045db @dhh Initial
dhh authored
525
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but …
jamis authored
526 # Delivers a TMail::Mail object. By default, it delivers the cached mail
98dc582 @lifo Merge docrails.
lifo authored
527 # object (from the <tt>create!</tt> method). If no cached mail object exists, and
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but …
jamis authored
528 # no alternate has been given as the parameter, this will fail.
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
529 def deliver!(mail = @mail)
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but …
jamis authored
530 raise "no mail object available for delivery!" unless mail
09f798b @josevalim Instrument create and deliver in ActionMailer.
josevalim authored
531
fbd3eb7 @jeremy Less verbose mail logging: just recipients for :info log level; the w…
jeremy authored
532 unless logger.nil?
be36455 @jeremy Ruby 1.9 compat: use Array() instead of #to_a.
jeremy authored
533 logger.info "Sent mail to #{Array(recipients).join(', ')}"
fbd3eb7 @jeremy Less verbose mail logging: just recipients for :info log level; the w…
jeremy authored
534 logger.debug "\n#{mail.encoded}"
535 end
256e800 @dhh Fixed quoting for all address headers, not just to #955 [Jamis Buck] …
dhh authored
536
2d7abe2 @josevalim Renamed Orchestra to Notifications once again [#3321 state:resolved]
josevalim authored
537 ActiveSupport::Notifications.instrument(:deliver_mail, :mail => @mail) do
09f798b @josevalim Instrument create and deliver in ActionMailer.
josevalim authored
538 begin
f4f7677 @matthewrudy abstract all of the ActionMailer delivery methods into their own clas…
matthewrudy authored
539 self.delivery_method.perform_delivery(mail) if perform_deliveries
09f798b @josevalim Instrument create and deliver in ActionMailer.
josevalim authored
540 rescue Exception => e # Net::SMTP errors or sendmail pipe errors
541 raise e if raise_delivery_errors
542 end
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
543 end
3fad0cd @dhh Added support for charsets for both subject and body. The default cha…
dhh authored
544
09f798b @josevalim Instrument create and deliver in ActionMailer.
josevalim authored
545 mail
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
546 end
3fad0cd @dhh Added support for charsets for both subject and body. The default cha…
dhh authored
547
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
548 private
f474f33 @jamis Move mailer initialization to a separate (overridable) method, so tha…
jamis authored
549 # Set up the default values for the various instance variables of this
550 # mailer. Subclasses may override this method to provide different
551 # defaults.
552 def initialize_defaults(method_name)
95e8740 @dhh Allow Mailers to have custom initialize methods that set default inst…
dhh authored
553 @charset ||= @@default_charset.dup
554 @content_type ||= @@default_content_type.dup
555 @implicit_parts_order ||= @@default_implicit_parts_order.dup
556 @template ||= method_name
6228220 @dhh Revert "Revert "Add layout functionality to mailers.""
dhh authored
557 @default_template_name = @action_name = @template
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
558 @mailer_name ||= self.class.name.underscore
95e8740 @dhh Allow Mailers to have custom initialize methods that set default inst…
dhh authored
559 @parts ||= []
560 @headers ||= {}
561 @body ||= {}
dca4d4e @jamis Multipart messages specify a MIME-Version header automatically #2003 …
jamis authored
562 @mime_version = @@default_mime_version.dup if @@default_mime_version
5fdc33c @mrduncan Default sent_on time to now in ActionMailer
mrduncan authored
563 @sent_on ||= Time.now
f474f33 @jamis Move mailer initialization to a separate (overridable) method, so tha…
jamis authored
564 end
565
eb9af20 @wycats Begin unifying the interface between ActionController and ActionView
wycats authored
566 def render_template(template, body)
ab83db9 Fixes ActionMailer to work with the ActionView refactoring
Yehuda Katz + Carl Lerche authored
567 if template.respond_to?(:mime_type)
568 @current_template_content_type = template.mime_type && template.mime_type.to_sym.to_s
1d4554d ActionMailer should respect content type when choosing layouts
Colin Curtin authored
569 end
8b340ab @josevalim Revert "Rename Orchestra to Notifications [#3321 state:resolved]"
josevalim authored
570
eb9af20 @wycats Begin unifying the interface between ActionController and ActionView
wycats authored
571 @template = initialize_template_class(body)
8b340ab @josevalim Revert "Rename Orchestra to Notifications [#3321 state:resolved]"
josevalim authored
572 layout = _pick_layout(layout, true) unless
ab83db9 Fixes ActionMailer to work with the ActionView refactoring
Yehuda Katz + Carl Lerche authored
573 ActionController::Base.exempt_from_layout.include?(template.handler)
0612fd0 @wycats Replace _render_template_with_layout with _render_template since the …
wycats authored
574 @template._render_template(template, layout, {})
eb9af20 @wycats Begin unifying the interface between ActionController and ActionView
wycats authored
575 ensure
576 @current_template_content_type = nil
577 end
578
579 def render_message(method_name, body)
7461227 @josh Ruby 1.9: Call join on template_root instead of to_s
josh authored
580 render :file => method_name, :body => body
1d4554d ActionMailer should respect content type when choosing layouts
Colin Curtin authored
581 ensure
582 @current_template_content_type = nil
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
583 end
ae1e852 @jamis Add a unified render method to ActionMailer (delegates to ActionView:…
jamis authored
584
585 def render(opts)
5b8e627 @jeremy AV expects options[:locals] to be a Hash
jeremy authored
586 opts[:locals] ||= {}
eb9af20 @wycats Begin unifying the interface between ActionController and ActionView
wycats authored
587 layout, file = opts.delete(:layout), opts[:file]
8b340ab @josevalim Revert "Rename Orchestra to Notifications [#3321 state:resolved]"
josevalim authored
588
6228220 @dhh Revert "Revert "Add layout functionality to mailers.""
dhh authored
589 begin
eb9af20 @wycats Begin unifying the interface between ActionController and ActionView
wycats authored
590 @template = initialize_template_class(opts.delete(:body))
8b340ab @josevalim Revert "Rename Orchestra to Notifications [#3321 state:resolved]"
josevalim authored
591
eb9af20 @wycats Begin unifying the interface between ActionController and ActionView
wycats authored
592 if file
593 prefix = mailer_name unless file =~ /\//
010a0c9 @wycats Rename find_by_parts and find_by_parts? to find and exists?
wycats authored
594 template = view_paths.find(file, {:formats => formats}, prefix)
eb9af20 @wycats Begin unifying the interface between ActionController and ActionView
wycats authored
595 end
596
8b340ab @josevalim Revert "Rename Orchestra to Notifications [#3321 state:resolved]"
josevalim authored
597 layout = _pick_layout(layout,
ab83db9 Fixes ActionMailer to work with the ActionView refactoring
Yehuda Katz + Carl Lerche authored
598 !template || ActionController::Base.exempt_from_layout.include?(template.handler))
eb9af20 @wycats Begin unifying the interface between ActionController and ActionView
wycats authored
599
600 if template
0612fd0 @wycats Replace _render_template_with_layout with _render_template since the …
wycats authored
601 @template._render_template(template, layout, opts)
eb9af20 @wycats Begin unifying the interface between ActionController and ActionView
wycats authored
602 elsif inline = opts[:inline]
603 @template._render_inline(inline, layout, opts)
604 end
6228220 @dhh Revert "Revert "Add layout functionality to mailers.""
dhh authored
605 end
606 end
607
608 def default_template_format
1d4554d ActionMailer should respect content type when choosing layouts
Colin Curtin authored
609 if @current_template_content_type
610 Mime::Type.lookup(@current_template_content_type).to_sym
611 else
612 :html
613 end
6228220 @dhh Revert "Revert "Add layout functionality to mailers.""
dhh authored
614 end
615
cb21db1 @josh Treat ActionMailer template_root as a view path set internally to avo…
josh authored
616 def template_root
617 self.class.template_root
618 end
619
620 def template_root=(root)
621 self.class.template_root = root
622 end
623
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
624 def template_path
0a132c2 Refactor ActionView::Path
Yehuda Katz + Carl Lerche authored
625 "#{mailer_name}"
db045db @dhh Initial
dhh authored
626 end
627
5ec990a @jamis Helper support for ActionMailer
jamis authored
628 def initialize_template_class(assigns)
441e4e2 @svenfuchs load plugin view_paths to action_mailer view_paths and make action_ma…
svenfuchs authored
629 template = ActionView::Base.new(self.class.view_paths, assigns, self)
eb9af20 @wycats Begin unifying the interface between ActionController and ActionView
wycats authored
630 template.formats = [default_template_format]
1d4554d ActionMailer should respect content type when choosing layouts
Colin Curtin authored
631 template
5ec990a @jamis Helper support for ActionMailer
jamis authored
632 end
633
5c98152 @jamis Better multipart support with implicit multipart/alternative and sort…
jamis authored
634 def sort_parts(parts, order = [])
635 order = order.collect { |s| s.downcase }
8b340ab @josevalim Revert "Rename Orchestra to Notifications [#3321 state:resolved]"
josevalim authored
636
5c98152 @jamis Better multipart support with implicit multipart/alternative and sort…
jamis authored
637 parts = parts.sort do |a, b|
638 a_ct = a.content_type.downcase
639 b_ct = b.content_type.downcase
640
641 a_in = order.include? a_ct
642 b_in = order.include? b_ct
643
644 s = case
645 when a_in && b_in
646 order.index(a_ct) <=> order.index(b_ct)
647 when a_in
648 -1
649 when b_in
650 1
651 else
652 a_ct <=> b_ct
653 end
654
655 # reverse the ordering because parts that come last are displayed
656 # first in mail clients
657 (s * -1)
658 end
659
660 parts
661 end
662
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
663 def create_mail
664 m = TMail::Mail.new
74a612c @dhh Added that delivery errors are caught in a way so the mail is still r…
dhh authored
665
cf6299d Add ActionMailer#reply_to. [#245 state:resolved]
Adam authored
666 m.subject, = quote_any_if_necessary(charset, subject)
667 m.to, m.from = quote_any_address_if_necessary(charset, recipients, from)
668 m.bcc = quote_address_if_necessary(bcc, charset) unless bcc.nil?
669 m.cc = quote_address_if_necessary(cc, charset) unless cc.nil?
670 m.reply_to = quote_address_if_necessary(reply_to, charset) unless reply_to.nil?
dca4d4e @jamis Multipart messages specify a MIME-Version header automatically #2003 …
jamis authored
671 m.mime_version = mime_version unless mime_version.nil?
cf6299d Add ActionMailer#reply_to. [#245 state:resolved]
Adam authored
672 m.date = sent_on.to_time rescue sent_on if sent_on
673
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
674 headers.each { |k, v| m[k] = v }
db045db @dhh Initial
dhh authored
675
db0e8ff @jamis Parse content-type apart before using it so that sub-parts of the hea…
jamis authored
676 real_content_type, ctype_attrs = parse_content_type
8b340ab @josevalim Revert "Rename Orchestra to Notifications [#3321 state:resolved]"
josevalim authored
677
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
678 if @parts.empty?
db0e8ff @jamis Parse content-type apart before using it so that sub-parts of the hea…
jamis authored
679 m.set_content_type(real_content_type, nil, ctype_attrs)
e201fc7 @josh use autoload instead of explicit requires for ActionMailer
josh authored
680 m.body = normalize_new_lines(body)
0a132c2 Refactor ActionView::Path
Yehuda Katz + Carl Lerche authored
681 elsif @parts.size == 1 && @parts.first.parts.empty?
682 m.set_content_type(real_content_type, nil, ctype_attrs)
683 m.body = normalize_new_lines(@parts.first.body)
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
684 else
685 if String === body
686 part = TMail::Mail.new
e201fc7 @josh use autoload instead of explicit requires for ActionMailer
josh authored
687 part.body = normalize_new_lines(body)
db0e8ff @jamis Parse content-type apart before using it so that sub-parts of the hea…
jamis authored
688 part.set_content_type(real_content_type, nil, ctype_attrs)
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
689 part.set_content_disposition "inline"
690 m.parts << part
691 end
3fad0cd @dhh Added support for charsets for both subject and body. The default cha…
dhh authored
692
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
693 @parts.each do |p|
694 part = (TMail::Mail === p ? p : p.to_mail(self))
695 m.parts << part
696 end
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored
697
49efa02 @jamis Nil charset caused subject line to be improperly quoted in implicitly…
jamis authored
698 if real_content_type =~ /multipart/
699 ctype_attrs.delete "charset"
700 m.set_content_type(real_content_type, nil, ctype_attrs)
701 end
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
702 end
256e800 @dhh Fixed quoting for all address headers, not just to #955 [Jamis Buck] …
dhh authored
703
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored
704 @mail = m
256e800 @dhh Fixed quoting for all address headers, not just to #955 [Jamis Buck] …
dhh authored
705 end
706
db045db @dhh Initial
dhh authored
707 end
e201fc7 @josh use autoload instead of explicit requires for ActionMailer
josh authored
708
709 Base.class_eval do
710 include Helpers
711 helper MailHelper
712 end
db045db @dhh Initial
dhh authored
713 end
Something went wrong with that request. Please try again.