Skip to content
This repository
Newer
Older
100644 749 lines (700 sloc) 31.414 kb
616ebb8f » josevalim
2009-12-28 Remove unused code paths and require mail only when it's needed.
1 require 'mail'
a2880827 » mikel
2009-12-30 Adding :transfer_encoding -> :content_transfer_encoding as part of Tm…
2 require 'action_mailer/tmail_compat'
c985a0ee » José Valim and Mikel Lindsaar
2010-01-23 Add some tests to collector with templates and any.
3 require 'action_mailer/collector'
41af6d9a » jeremy
2010-03-17 Use Array.wrap not Array()
4 require 'active_support/core_ext/array/wrap'
76f024ac » fxn
2010-03-28 adds missing requires for Object#blank? and Object#present?
5 require 'active_support/core_ext/object/blank'
fa5f9369 » spastorino
2010-05-16 Added missing require, we are using bind method defined on active_sup…
6 require 'active_support/core_ext/proc'
6788db82 » josevalim
2010-06-24 Move Rails::LogSubscriber to ActiveSupport::LogSubscriber, allowing f…
7 require 'action_mailer/log_subscriber'
a63caa4c » Yehuda Katz + Carl Lerche
2009-06-15 Get tests to run (with failures) without old base around
8
c4590d57 » dhh
2006-03-28 Fixed docs
9 module ActionMailer #:nodoc:
98dc5827 » lifo
2008-05-25 Merge docrails.
10 # Action Mailer allows you to send email from your application using a mailer model and views.
db045dbb » dhh
2004-11-24 Initial
11 #
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
12 # = Mailer Models
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
13 #
98dc5827 » lifo
2008-05-25 Merge docrails.
14 # 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…
15 #
f44a0b1d » romdi
2010-02-06 fix usage examples and more to use new invocations
16 # $ rails generate mailer Notifier
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
17 #
058f7fea » mikel
2010-05-02 Cleaning up Action Mailer spelling with and without the space
18 # The generated model inherits from <tt>ActionMailer::Base</tt>. Emails are defined by creating methods
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
19 # within the model which are then used to set variables to be used in the mail template, to
20 # change options on the mail, or to add attachments.
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
21 #
22 # Examples:
23 #
24 # class Notifier < ActionMailer::Base
452bb1e4 » jeremy
2010-01-27 Rename 'defaults' class method to 'default' to reflect that it's a de…
25 # default :from => 'no-reply@example.com',
26 # :return_path => 'system@example.com'
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
27 #
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
28 # def welcome(recipient)
29 # @account = recipient
65899765 » José Valim and Mikel Lindsaar
2010-01-26 Remove old files, add some information to docs and improve test suite.
30 # mail(:to => recipient.email_address_with_name,
31 # :bcc => ["bcc@example.com", "Order Watcher <watcher@example.com>"])
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
32 # end
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
33 # end
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
34 #
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
35 # Within the mailer method, you have access to the following methods:
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
36 #
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
37 # * <tt>attachments[]=</tt> - Allows you to add attachments to your email in an intuitive
38 # manner; <tt>attachments['filename.png'] = File.read('path/to/filename.png')</tt>
65899765 » José Valim and Mikel Lindsaar
2010-01-26 Remove old files, add some information to docs and improve test suite.
39 #
3762362e » mikel
2010-06-07 Updating readme for ActionMailer::Base
40 # * <tt>attachments.inline[]=</tt> - Allows you to add an inline attachment to your email
41 # in the same manner as <tt>attachments[]=</tt>
42 #
bb2c7b43 » mikel
2010-01-29 Updating Action Mailer documentation
43 # * <tt>headers[]=</tt> - Allows you to specify any header field in your email such
44 # as <tt>headers['X-No-Spam'] = 'True'</tt>. Note, while most fields (like <tt>To:</tt>
45 # <tt>From:</tt> can only appear once in an email header, other fields like <tt>X-Anything</tt>
46 # can appear multiple times. If you want to change a field that can appear multiple times,
47 # you need to set it to nil first so that Mail knows you are replacing it, not adding
48 # another field of the same name.)
65899765 » José Valim and Mikel Lindsaar
2010-01-26 Remove old files, add some information to docs and improve test suite.
49 #
9520166f » mikel
2010-01-27 Fixed up being able to pass random headers in with headers, or mail. …
50 # * <tt>headers(hash)</tt> - Allows you to specify multiple headers in your email such
51 # as <tt>headers({'X-No-Spam' => 'True', 'In-Reply-To' => '1234@message.id'})</tt>
52 #
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
53 # * <tt>mail</tt> - Allows you to specify your email to send.
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
54 #
9520166f » mikel
2010-01-27 Fixed up being able to pass random headers in with headers, or mail. …
55 # The hash passed to the mail method allows you to specify any header that a Mail::Message
bb2c7b43 » mikel
2010-01-29 Updating Action Mailer documentation
56 # will accept (any valid Email header including optional fields).
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
57 #
58 # The mail method, if not passed a block, will inspect your views and send all the views with
bb2c7b43 » mikel
2010-01-29 Updating Action Mailer documentation
59 # the same name as the method, so the above action would send the +welcome.text.plain.erb+ view
60 # file as well as the +welcome.text.html.erb+ view file in a +multipart/alternative+ email.
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
61 #
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
62 # If you want to explicitly render only certain templates, pass a block:
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
63 #
c1251160 » dchelimsky
2010-06-12 docfix (email instead of emai)
64 # mail(:to => user.email) do |format|
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
65 # format.text
66 # format.html
67 # end
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
68 #
65899765 » José Valim and Mikel Lindsaar
2010-01-26 Remove old files, add some information to docs and improve test suite.
69 # The block syntax is useful if also need to specify information specific to a part:
70 #
c1251160 » dchelimsky
2010-06-12 docfix (email instead of emai)
71 # mail(:to => user.email) do |format|
65899765 » José Valim and Mikel Lindsaar
2010-01-26 Remove old files, add some information to docs and improve test suite.
72 # format.text(:content_transfer_encoding => "base64")
73 # format.html
74 # end
75 #
bb2c7b43 » mikel
2010-01-29 Updating Action Mailer documentation
76 # Or even to render a special view:
65899765 » José Valim and Mikel Lindsaar
2010-01-26 Remove old files, add some information to docs and improve test suite.
77 #
c1251160 » dchelimsky
2010-06-12 docfix (email instead of emai)
78 # mail(:to => user.email) do |format|
65899765 » José Valim and Mikel Lindsaar
2010-01-26 Remove old files, add some information to docs and improve test suite.
79 # format.text
80 # format.html { render "some_other_template" }
81 # end
82 #
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
83 # = Mailer views
84 #
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
85 # Like Action Controller, each mailer class has a corresponding view directory in which each
86 # method of the class looks for a template with its name.
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
87 #
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
88 # To define a template to be used with a mailing, create an <tt>.erb</tt> file with the same
89 # name as the method in your mailer model. For example, in the mailer defined above, the template at
bb2c7b43 » mikel
2010-01-29 Updating Action Mailer documentation
90 # <tt>app/views/notifier/signup_notification.text.plain.erb</tt> would be used to generate the email.
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
91 #
92 # Variables defined in the model are accessible as instance variables in the view.
93 #
94 # Emails by default are sent in plain text, so a sample view for our model example might look like this:
95 #
96 # Hi <%= @account.name %>,
97 # Thanks for joining our service! Please check back often.
98 #
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
99 # You can even use Action Pack helpers in these views. For example:
100 #
101 # You got a new note!
ee70d1b6 » josevalim
2009-12-25 adv_attr_accessors in ActionMailer are not sent to the views, use the…
102 # <%= truncate(@note.body, 25) %>
103 #
65899765 » José Valim and Mikel Lindsaar
2010-01-26 Remove old files, add some information to docs and improve test suite.
104 # If you need to access the subject, from or the recipients in the view, you can do that through message object:
ee70d1b6 » josevalim
2009-12-25 adv_attr_accessors in ActionMailer are not sent to the views, use the…
105 #
65899765 » José Valim and Mikel Lindsaar
2010-01-26 Remove old files, add some information to docs and improve test suite.
106 # You got a new note from <%= message.from %>!
ee70d1b6 » josevalim
2009-12-25 adv_attr_accessors in ActionMailer are not sent to the views, use the…
107 # <%= truncate(@note.body, 25) %>
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
108 #
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
109 #
4809dcc1 » Cody Fauser
2008-04-21 * Remove default_url_options from mailer generator
110 # = Generating URLs
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
111 #
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
112 # URLs can be generated in mailer views using <tt>url_for</tt> or named routes. Unlike controllers from
bb2c7b43 » mikel
2010-01-29 Updating Action Mailer documentation
113 # Action Pack, the mailer instance doesn't have any context about the incoming request, so you'll need
114 # to provide all of the details needed to generate a URL.
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
115 #
4809dcc1 » Cody Fauser
2008-04-21 * Remove default_url_options from mailer generator
116 # 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…
117 #
4809dcc1 » Cody Fauser
2008-04-21 * Remove default_url_options from mailer generator
118 # <%= url_for(:host => "example.com", :controller => "welcome", :action => "greeting") %>
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
119 #
4809dcc1 » Cody Fauser
2008-04-21 * Remove default_url_options from mailer generator
120 # 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…
121 #
4809dcc1 » Cody Fauser
2008-04-21 * Remove default_url_options from mailer generator
122 # <%= users_url(:host => "example.com") %>
123 #
bb2c7b43 » mikel
2010-01-29 Updating Action Mailer documentation
124 # You will want to avoid using the <tt>name_of_route_path</tt> form of named routes because it doesn't
125 # make sense to generate relative URLs in email messages.
4809dcc1 » Cody Fauser
2008-04-21 * Remove default_url_options from mailer generator
126 #
bb2c7b43 » mikel
2010-01-29 Updating Action Mailer documentation
127 # It is also possible to set a default host that will be used in all mailers by setting the <tt>:host</tt>
128 # option in the <tt>ActionMailer::Base.default_url_options</tt> hash as follows:
4809dcc1 » Cody Fauser
2008-04-21 * Remove default_url_options from mailer generator
129 #
130 # ActionMailer::Base.default_url_options[:host] = "example.com"
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
131 #
dc4eec11 » lifo
2008-05-09 Merge docrails:
132 # 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
133 #
134 # config.action_mailer.default_url_options = { :host => "example.com" }
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
135 #
4809dcc1 » Cody Fauser
2008-04-21 * Remove default_url_options from mailer generator
136 # If you do decide to set a default <tt>:host</tt> for your mailers you will want to use the
bb2c7b43 » mikel
2010-01-29 Updating Action Mailer documentation
137 # <tt>:only_path => false</tt> option when using <tt>url_for</tt>. This will ensure that absolute URLs are
138 # generated because the <tt>url_for</tt> view helper will, by default, generate relative URLs when a
139 # <tt>:host</tt> option isn't explicitly provided.
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
140 #
141 # = Sending mail
142 #
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
143 # 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, …
144 # for delivery later:
145 #
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
146 # Notifier.welcome(david).deliver # sends the email
147 # mail = Notifier.welcome(david) # => a Mail::Message object
148 # mail.deliver # sends the email
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
149 #
bb2c7b43 » mikel
2010-01-29 Updating Action Mailer documentation
150 # You never instantiate your mailer class. Rather, you just call the method you defined on the class itself.
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
151 #
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
152 # = Multipart Emails
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
153 #
98dc5827 » lifo
2008-05-25 Merge docrails.
154 # 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, …
155 # detect and use multipart templates, where each template is named after the name of the action, followed
156 # 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…
157 #
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
158 # For example, if the following templates existed:
21187c0f » dhh
2007-02-21 Apply the rest of Chads patch
159 # * signup_notification.text.plain.erb
160 # * signup_notification.text.html.erb
161 # * signup_notification.text.xml.builder
65899765 » José Valim and Mikel Lindsaar
2010-01-26 Remove old files, add some information to docs and improve test suite.
162 # * signup_notification.text.yaml.erb
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
163 #
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
164 # Each would be rendered and added as a separate part to the message, with the corresponding content
165 # type. The content type for the entire message is automatically set to <tt>multipart/alternative</tt>,
166 # which indicates that the email contains multiple different representations of the same email
167 # body. The same instance variables defined in the action are passed to all email templates.
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
168 #
46f30f90 » lifo
2008-05-16 Merge documentation changes from docrails.
169 # Implicit template rendering is not performed if any attachments or parts have been added to the email.
170 # This means that you'll have to manually add each part to the email and set the content type of the email
171 # to <tt>multipart/alternative</tt>.
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
172 #
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
173 # = Attachments
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
174 #
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
175 # You can see above how to make a multipart HTML / Text email, to send attachments is just
176 # as easy:
0a407bca » Marcel Molina
2006-05-10 ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
177 #
178 # class ApplicationMailer < ActionMailer::Base
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
179 # def welcome(recipient)
3762362e » mikel
2010-06-07 Updating readme for ActionMailer::Base
180 # attachments['free_book.pdf'] = File.read('path/to/file.pdf')
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
181 # mail(:to => recipient, :subject => "New account information")
db045dbb » dhh
2004-11-24 Initial
182 # end
3b0e1d90 » josh
2008-05-14 Prefer string core_ext inflector methods over directly accessing Infl…
183 # end
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
184 #
bb2c7b43 » mikel
2010-01-29 Updating Action Mailer documentation
185 # Which will (if it had both a <tt>welcome.text.plain.erb</tt> and <tt>welcome.text.html.erb</tt>
ccf9577a » dolzenko
2010-06-11 Fix a bunch of minor spelling mistakes
186 # template in the view directory), send a complete <tt>multipart/mixed</tt> email with two parts,
bb2c7b43 » mikel
2010-01-29 Updating Action Mailer documentation
187 # the first part being a <tt>multipart/alternative</tt> with the text and HTML email parts inside,
188 # and the second being a <tt>application/pdf</tt> with a Base64 encoded copy of the file.pdf book
189 # with the filename +free_book.pdf+.
c927aa0f » dhh
2004-12-16 Updated documentation
190 #
3762362e » mikel
2010-06-07 Updating readme for ActionMailer::Base
191 # = Inline Attachments
192 #
193 # You can also specify that a file should be displayed inline with other HTML. For example a
194 # corporate logo or a photo or the like.
195 #
196 # To do this is simple, in the Mailer:
197 #
198 # class ApplicationMailer < ActionMailer::Base
199 # def welcome(recipient)
200 # attachments.inline['photo.png'] = File.read('path/to/photo.png')
201 # mail(:to => recipient, :subject => "Here is what we look like")
202 # end
203 # end
204 #
205 # And then to reference the image in the view, you create a <tt>welcome.html.erb</tt> file and
206 # make a call to +image_tag+ passing in the attachment you want to display and then call
207 # +url+ on the attachment to get the relative content id path for the image source:
208 #
209 # <h1>Please Don't Cringe</h1>
210 #
211 # <%= image_tag attachments['photo.png'].url -%>
212 #
f17159b0 » fxn
2010-06-14 edit pass: the names of Rails components have a space, ie, "Active Re…
213 # As we are using Action View's +image_tag+ method, you can pass in any other options you want:
3762362e » mikel
2010-06-07 Updating readme for ActionMailer::Base
214 #
215 # <h1>Please Don't Cringe</h1>
216 #
217 # <%= image_tag attachments['photo.png'].url, :alt => 'Our Photo', :class => 'photo' -%>
218 #
cefc136e » mikel
2010-02-22 Adding options to register observers and interceptors through ActionM…
219 # = Observing and Intercepting Mails
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
220 #
058f7fea » mikel
2010-05-02 Cleaning up Action Mailer spelling with and without the space
221 # Action Mailer provides hooks into the Mail observer and interceptor methods. These allow you to
cefc136e » mikel
2010-02-22 Adding options to register observers and interceptors through ActionM…
222 # register objects that are called during the mail delivery life cycle.
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
223 #
cefc136e » mikel
2010-02-22 Adding options to register observers and interceptors through ActionM…
224 # An observer object must implement the <tt>:delivered_email(message)</tt> method which will be
225 # called once for every email sent after the email has been sent.
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
226 #
cefc136e » mikel
2010-02-22 Adding options to register observers and interceptors through ActionM…
227 # An interceptor object must implement the <tt>:delivering_email(message)</tt> method which will be
228 # called before the email is sent, allowing you to make modifications to the email before it hits
229 # the delivery agents. Your object should make and needed modifications directly to the passed
230 # in Mail::Message instance.
20bd4bd3 » dhh
2006-09-02 Updated docs and otherwise
231 #
fb30feb4 » mikel
2010-05-02 Adding more docs to ActionMailer
232 # = Default Hash
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
233 #
058f7fea » mikel
2010-05-02 Cleaning up Action Mailer spelling with and without the space
234 # Action Mailer provides some intelligent defaults for your emails, these are usually specified in a
fb30feb4 » mikel
2010-05-02 Adding more docs to ActionMailer
235 # default method inside the class definition:
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
236 #
fb30feb4 » mikel
2010-05-02 Adding more docs to ActionMailer
237 # class Notifier < ActionMailer::Base
238 # default :sender => 'system@example.com'
239 # end
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
240 #
fb30feb4 » mikel
2010-05-02 Adding more docs to ActionMailer
241 # You can pass in any header value that a <tt>Mail::Message</tt>, out of the box, <tt>ActionMailer::Base</tt>
242 # sets the following:
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
243 #
fb30feb4 » mikel
2010-05-02 Adding more docs to ActionMailer
244 # * <tt>:mime_version => "1.0"</tt>
245 # * <tt>:charset => "UTF-8",</tt>
246 # * <tt>:content_type => "text/plain",</tt>
247 # * <tt>:parts_order => [ "text/plain", "text/enriched", "text/html" ]</tt>
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
248 #
fb30feb4 » mikel
2010-05-02 Adding more docs to ActionMailer
249 # <tt>parts_order</tt> and <tt>charset</tt> are not actually valid <tt>Mail::Message</tt> header fields,
058f7fea » mikel
2010-05-02 Cleaning up Action Mailer spelling with and without the space
250 # but Action Mailer translates them appropriately and sets the correct values.
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
251 #
fb30feb4 » mikel
2010-05-02 Adding more docs to ActionMailer
252 # As you can pass in any header, you need to either quote the header as a string, or pass it in as
253 # an underscorised symbol, so the following will work:
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
254 #
fb30feb4 » mikel
2010-05-02 Adding more docs to ActionMailer
255 # class Notifier < ActionMailer::Base
256 # default 'Content-Transfer-Encoding' => '7bit',
257 # :content_description => 'This is a description'
258 # end
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
259 #
058f7fea » mikel
2010-05-02 Cleaning up Action Mailer spelling with and without the space
260 # Finally, Action Mailer also supports passing <tt>Proc</tt> objects into the default hash, so you
fb30feb4 » mikel
2010-05-02 Adding more docs to ActionMailer
261 # can define methods that evaluate as the message is being generated:
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
262 #
fb30feb4 » mikel
2010-05-02 Adding more docs to ActionMailer
263 # class Notifier < ActionMailer::Base
264 # default 'X-Special-Header' => Proc.new { my_method }
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
265 #
fb30feb4 » mikel
2010-05-02 Adding more docs to ActionMailer
266 # private
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
267 #
fb30feb4 » mikel
2010-05-02 Adding more docs to ActionMailer
268 # def my_method
269 # 'some complex call'
270 # end
271 # end
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
272 #
fb30feb4 » mikel
2010-05-02 Adding more docs to ActionMailer
273 # Note that the proc is evaluated right at the start of the mail message generation, so if you
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
274 # set something in the defaults using a proc, and then set the same thing inside of your
fb30feb4 » mikel
2010-05-02 Adding more docs to ActionMailer
275 # mailer method, it will get over written by the mailer method.
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
276 #
c927aa0f » dhh
2004-12-16 Updated documentation
277 # = Configuration options
278 #
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
279 # These options are specified on the class level, like
fb30feb4 » mikel
2010-05-02 Adding more docs to ActionMailer
280 # <tt>ActionMailer::Base.template_root = "/my/templates"</tt>
c927aa0f » dhh
2004-12-16 Updated documentation
281 #
fb30feb4 » mikel
2010-05-02 Adding more docs to ActionMailer
282 # * <tt>default</tt> - You can pass this in at a class level as well as within the class itself as
283 # per the above section.
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
284 #
c927aa0f » dhh
2004-12-16 Updated documentation
285 # * <tt>logger</tt> - the logger is used for generating information on the mailing run if available.
286 # Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers.
287 #
64092de2 » fxn
2008-05-02 Improve documentation coverage and markup
288 # * <tt>smtp_settings</tt> - Allows detailed configuration for <tt>:smtp</tt> delivery method:
bb2c7b43 » mikel
2010-01-29 Updating Action Mailer documentation
289 # * <tt>:address</tt> - Allows you to use a remote mail server. Just change it from its default
290 # "localhost" setting.
dc4eec11 » lifo
2008-05-09 Merge docrails:
291 # * <tt>:port</tt> - On the off chance that your mail server doesn't run on port 25, you can change it.
292 # * <tt>:domain</tt> - If you need to specify a HELO domain, you can do it here.
293 # * <tt>:user_name</tt> - If your mail server requires authentication, set the username in this setting.
294 # * <tt>:password</tt> - If your mail server requires authentication, set the password in this setting.
bb2c7b43 » mikel
2010-01-29 Updating Action Mailer documentation
295 # * <tt>:authentication</tt> - If your mail server requires authentication, you need to specify the
296 # authentication type here.
46f30f90 » lifo
2008-05-16 Merge documentation changes from docrails.
297 # This is a symbol and one of <tt>:plain</tt>, <tt>:login</tt>, <tt>:cram_md5</tt>.
bb2c7b43 » mikel
2010-01-29 Updating Action Mailer documentation
298 # * <tt>:enable_starttls_auto</tt> - When set to true, detects if STARTTLS is enabled in your SMTP server
299 # and starts to use it.
c927aa0f » dhh
2004-12-16 Updated documentation
300 #
46f30f90 » lifo
2008-05-16 Merge documentation changes from docrails.
301 # * <tt>sendmail_settings</tt> - Allows you to override options for the <tt>:sendmail</tt> delivery method.
302 # * <tt>:location</tt> - The location of the sendmail executable. Defaults to <tt>/usr/sbin/sendmail</tt>.
bb2c7b43 » mikel
2010-01-29 Updating Action Mailer documentation
303 # * <tt>:arguments</tt> - The command line arguments. Defaults to <tt>-i -t</tt> with <tt>-f sender@addres</tt>
304 # added automatically before the message is sent.
dc4eec11 » lifo
2008-05-09 Merge docrails:
305 #
fbe6c3c1 » edavis10
2009-08-07 Adds a :file delivery_method to save email to a file on disk
306 # * <tt>file_settings</tt> - Allows you to override options for the <tt>:file</tt> delivery method.
bb2c7b43 » mikel
2010-01-29 Updating Action Mailer documentation
307 # * <tt>:location</tt> - The directory into which emails will be written. Defaults to the application
308 # <tt>tmp/mails</tt>.
fbe6c3c1 » edavis10
2009-08-07 Adds a :file delivery_method to save email to a file on disk
309 #
dc4eec11 » lifo
2008-05-09 Merge docrails:
310 # * <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
311 #
bb2c7b43 » mikel
2010-01-29 Updating Action Mailer documentation
312 # * <tt>delivery_method</tt> - Defines a delivery method. Possible values are <tt>:smtp</tt> (default),
313 # <tt>:sendmail</tt>, <tt>:test</tt>, and <tt>:file</tt>. Or you may provide a custom delivery method
314 # object eg. MyOwnDeliveryMethodClass.new. See the Mail gem documentation on the interface you need to
315 # implement for a custom delivery agent.
c927aa0f » dhh
2004-12-16 Updated documentation
316 #
bb2c7b43 » mikel
2010-01-29 Updating Action Mailer documentation
317 # * <tt>perform_deliveries</tt> - Determines whether emails are actually sent from Action Mailer when you
318 # call <tt>.deliver</tt> on an mail message or on an Action Mailer method. This is on by default but can
319 # be turned off to aid in functional testing.
c927aa0f » dhh
2004-12-16 Updated documentation
320 #
bb2c7b43 » mikel
2010-01-29 Updating Action Mailer documentation
321 # * <tt>deliveries</tt> - Keeps an array of all the emails sent out through the Action Mailer with
322 # <tt>delivery_method :test</tt>. Most useful for unit and functional testing.
af56c806 » dhh
2005-02-24 Updated documentation
323 #
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
324 # * <tt>default_charset</tt> - This is now deprecated, use the +default+ method above to
21dcc20e » mikel
2010-01-27 Fixed up documentation to reflect code change and cleaned up tests of…
325 # set the default +:charset+.
c2e7851f » josevalim
2009-01-11 Add ActionMailer::Base#enable_starttls_auto option for enabling/disab…
326 #
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
327 # * <tt>default_content_type</tt> - This is now deprecated, use the +default+ method above
21dcc20e » mikel
2010-01-27 Fixed up documentation to reflect code change and cleaned up tests of…
328 # to set the default +:content_type+.
c2e7851f » josevalim
2009-01-11 Add ActionMailer::Base#enable_starttls_auto option for enabling/disab…
329 #
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
330 # * <tt>default_mime_version</tt> - This is now deprecated, use the +default+ method above
21dcc20e » mikel
2010-01-27 Fixed up documentation to reflect code change and cleaned up tests of…
331 # to set the default +:mime_version+.
c2e7851f » josevalim
2009-01-11 Add ActionMailer::Base#enable_starttls_auto option for enabling/disab…
332 #
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
333 # * <tt>default_implicit_parts_order</tt> - This is now deprecated, use the +default+ method above
21dcc20e » mikel
2010-01-27 Fixed up documentation to reflect code change and cleaned up tests of…
334 # to set the default +:parts_order+. Parts Order is used when a message is built implicitly
335 # (i.e. multiple parts are assembled from templates which specify the content type in their
336 # filenames) this variable controls how the parts are ordered.
4964d3b0 » josevalim
2009-12-22 Make ActionMailer::Base inherit from AbstractController::Base
337 class Base < AbstractController::Base
dbcf01e6 » mikel
2010-04-08 Removing quoting.rb, upgrade to 2.1.3.6, changing all utf-8 reference…
338 include DeliveryMethods
f30d73ba » José Valim and Mikel Lindsaar
2010-01-24 Add new class delivery method API.
339 abstract!
340
c03c40b4 » josevalim
2009-12-31 Expose a _render_partial hook as thhe _render_template one and make u…
341 include AbstractController::Logger
83f4d86a » dhh
2009-12-20 Rename the RenderingController module to just plain Rendering
342 include AbstractController::Rendering
a9751a70 » josevalim
2009-10-17 Refactor ActionMailer layout and remove legacy one.
343 include AbstractController::Layouts
684c2dc2 » josevalim
2009-10-18 Remove ActionMailer helpers and rely on AbstractController one.
344 include AbstractController::Helpers
48a3985d » josevalim
2010-01-26 Also include translation in ActionMailer.
345 include AbstractController::Translation
08baa343 » dhh
2010-06-02 Extract assets paths and make them available to Action Mailer as well
346 include AbstractController::AssetPaths
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
347
ee70d1b6 » josevalim
2009-12-25 adv_attr_accessors in ActionMailer are not sent to the views, use the…
348 helper ActionMailer::MailHelper
7409b734 » José Valim and Mikel Lindsaar
2010-01-24 Some refactoring.
349
5dead5bb » José Valim and Mikel Lindsaar
2010-01-24 Maintain old_api and deprecated_api in different files.
350 include ActionMailer::OldApi
f30d73ba » José Valim and Mikel Lindsaar
2010-01-24 Add new class delivery method API.
351 include ActionMailer::DeprecatedApi
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
352
cefc136e » mikel
2010-02-22 Adding options to register observers and interceptors through ActionM…
353 delegate :register_observer, :to => Mail
354 delegate :register_interceptor, :to => Mail
7409b734 » José Valim and Mikel Lindsaar
2010-01-24 Some refactoring.
355
c927aa0f » dhh
2004-12-16 Updated documentation
356 private_class_method :new #:nodoc:
db045dbb » dhh
2004-11-24 Initial
357
e5ab4b0d » jeremy
2010-01-31 Convert to class_attribute
358 class_attribute :default_params
9dd65c36 » José Valim and Mikel Lindsaar
2010-01-26 Make defaults accept a hash.
359 self.default_params = {
360 :mime_version => "1.0",
dbcf01e6 » mikel
2010-04-08 Removing quoting.rb, upgrade to 2.1.3.6, changing all utf-8 reference…
361 :charset => "UTF-8",
9dd65c36 » José Valim and Mikel Lindsaar
2010-01-26 Make defaults accept a hash.
362 :content_type => "text/plain",
363 :parts_order => [ "text/plain", "text/enriched", "text/html" ]
e5ab4b0d » jeremy
2010-01-31 Convert to class_attribute
364 }.freeze
e1c13186 » José Valim and Mikel Lindsaar
2010-01-25 Added delivers_from.
365
eda17194 » jamis
2005-07-31 ActionMailer::Base.deliver(email) had been accidentally removed, but …
366 class << self
0b05acd4 » mikel
2010-01-26 Implementing class level :defaults hash, instead of delivers_from et al
367
bd5ed651 » technoweenie
2007-11-26 Update ActionMailer so it treats ActionView the same way that ActionC…
368 def mailer_name
369 @mailer_name ||= name.underscore
370 end
0750304c » mikel
2010-01-16 Migrated over to Mail doing delivery.
371 attr_writer :mailer_name
372 alias :controller_path :mailer_name
81c416b7 » josevalim
2009-10-28 More refactoring on ActionMailer::Base.
373
e5ab4b0d » jeremy
2010-01-31 Convert to class_attribute
374 def default(value = nil)
375 self.default_params = default_params.merge(value).freeze if value
376 default_params
9dd65c36 » José Valim and Mikel Lindsaar
2010-01-26 Make defaults accept a hash.
377 end
378
59f1df1b » jamis
2005-10-16 Update/extend ActionMailer documentation (rdoc)
379 # Receives a raw email, parses it into an email object, decodes it,
380 # instantiates a new mailer, and passes the email object to the mailer
98dc5827 » lifo
2008-05-25 Merge docrails.
381 # object's +receive+ method. If you want your mailer to be able to
382 # process incoming messages, you'll need to implement a +receive+
bb2c7b43 » mikel
2010-01-29 Updating Action Mailer documentation
383 # method that accepts the raw email string as a parameter:
59f1df1b » jamis
2005-10-16 Update/extend ActionMailer documentation (rdoc)
384 #
385 # class MyMailer < ActionMailer::Base
386 # def receive(mail)
387 # ...
388 # end
389 # end
704daad7 » josevalim
2010-01-15 Ensure we just send Ruby Stdlib objects in ActionMailer notifications.
390 def receive(raw_mail)
731d4392 » jaggederest
2010-04-27 Change event namespace ordering to most-significant first [#4504 stat…
391 ActiveSupport::Notifications.instrument("receive.action_mailer") do |payload|
704daad7 » josevalim
2010-01-15 Ensure we just send Ruby Stdlib objects in ActionMailer notifications.
392 mail = Mail.new(raw_mail)
393 set_payload_for_mail(payload, mail)
2a6bc126 » josevalim
2010-01-13 Add subscriber to ActionMailer.
394 new.receive(mail)
395 end
eda17194 » jamis
2005-07-31 ActionMailer::Base.deliver(email) had been accidentally removed, but …
396 end
397
bb2c7b43 » mikel
2010-01-29 Updating Action Mailer documentation
398 # Wraps an email delivery inside of Active Support Notifications instrumentation. This
de65c82b » rizwanreza
2010-06-15 Changes call backs to callbacks.
399 # method is actually called by the <tt>Mail::Message</tt> object itself through a callback
bb2c7b43 » mikel
2010-01-29 Updating Action Mailer documentation
400 # when you call <tt>:deliver</tt> on the Mail::Message, calling +deliver_mail+ directly
401 # and passing a Mail::Message will do nothing except tell the logger you sent the email.
e4a989e9 » José Valim and Mikel Lindsaar
2010-01-25 Added delivery_handler method to mail and implemented in ActionMailer…
402 def deliver_mail(mail) #:nodoc:
731d4392 » jaggederest
2010-04-27 Change event namespace ordering to most-significant first [#4504 stat…
403 ActiveSupport::Notifications.instrument("deliver.action_mailer") do |payload|
258ca148 » José Valim and Mikel Lindsaar
2010-01-24 Delegated ActionMailer::Base.deliveries to Mail.deliveries, added cal…
404 self.set_payload_for_mail(payload, mail)
ace74974 » José Valim and Mikel Lindsaar
2010-01-25 Got AM working with Mail yield on delivery_handler and updated tests
405 yield # Let Mail do the delivery actions
258ca148 » José Valim and Mikel Lindsaar
2010-01-24 Delegated ActionMailer::Base.deliveries to Mail.deliveries, added cal…
406 end
407 end
408
99f960a3 » José Valim and Mikel Lindsaar
2010-01-24 Handle some TODOs and deprecations.
409 def respond_to?(method, *args) #:nodoc:
410 super || action_methods.include?(method.to_s)
411 end
412
413 protected
414
704daad7 » josevalim
2010-01-15 Ensure we just send Ruby Stdlib objects in ActionMailer notifications.
415 def set_payload_for_mail(payload, mail) #:nodoc:
99f960a3 » José Valim and Mikel Lindsaar
2010-01-24 Handle some TODOs and deprecations.
416 payload[:mailer] = self.name
c905fce3 » josevalim
2010-01-15 Add message_id to AM payload and don't send bcc and cc if they were n…
417 payload[:message_id] = mail.message_id
418 payload[:subject] = mail.subject
419 payload[:to] = mail.to
420 payload[:from] = mail.from
421 payload[:bcc] = mail.bcc if mail.bcc.present?
422 payload[:cc] = mail.cc if mail.cc.present?
423 payload[:date] = mail.date
424 payload[:mail] = mail.encoded
704daad7 » josevalim
2010-01-15 Ensure we just send Ruby Stdlib objects in ActionMailer notifications.
425 end
f30d73ba » José Valim and Mikel Lindsaar
2010-01-24 Add new class delivery method API.
426
99f960a3 » José Valim and Mikel Lindsaar
2010-01-24 Handle some TODOs and deprecations.
427 def method_missing(method, *args) #:nodoc:
f30d73ba » José Valim and Mikel Lindsaar
2010-01-24 Add new class delivery method API.
428 if action_methods.include?(method.to_s)
429 new(method, *args).message
430 else
431 super
432 end
433 end
eda17194 » jamis
2005-07-31 ActionMailer::Base.deliver(email) had been accidentally removed, but …
434 end
435
7409b734 » José Valim and Mikel Lindsaar
2010-01-24 Some refactoring.
436 attr_internal :message
437
6ba94460 » José Valim and Mikel Lindsaar
2010-01-23 Make implicit and explicit templates pass through the same part creat…
438 # Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer
439 # will be initialized according to the named method. If not, the mailer will
440 # remain uninitialized (useful when you only need to invoke the "receive"
441 # method, for instance).
442 def initialize(method_name=nil, *args)
443 super()
7409b734 » José Valim and Mikel Lindsaar
2010-01-24 Some refactoring.
444 @_message = Mail.new
6ba94460 » José Valim and Mikel Lindsaar
2010-01-23 Make implicit and explicit templates pass through the same part creat…
445 process(method_name, *args) if method_name
446 end
447
3fc609ee » josevalim
2010-04-12 Fix ActionMailer test broken in 99d5459
448 def process(*args) #:nodoc:
449 lookup_context.skip_default_locale!
450 super
451 end
452
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
453 # Allows you to pass random and unusual headers to the new +Mail::Message+ object
454 # which will add them to itself.
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
455 #
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
456 # headers['X-Special-Domain-Specific-Header'] = "SecretValue"
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
457 #
9520166f » mikel
2010-01-27 Fixed up being able to pass random headers in with headers, or mail. …
458 # You can also pass a hash into headers of header field names and values, which
459 # will then be set on the Mail::Message object:
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
460 #
05c4ad9d » José Valim and Mikel Lindsaar
2010-01-26 Tidy up tests and docs.
461 # headers 'X-Special-Domain-Specific-Header' => "SecretValue",
462 # 'In-Reply-To' => incoming.message_id
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
463 #
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
464 # The resulting Mail::Message will have the following in it's header:
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
465 #
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
466 # X-Special-Domain-Specific-Header: SecretValue
7409b734 » José Valim and Mikel Lindsaar
2010-01-24 Some refactoring.
467 def headers(args=nil)
468 if args
9520166f » mikel
2010-01-27 Fixed up being able to pass random headers in with headers, or mail. …
469 @_message.headers(args)
7409b734 » José Valim and Mikel Lindsaar
2010-01-24 Some refactoring.
470 else
471 @_message
472 end
473 end
c34cfcc2 » mikel
2010-01-20 Created mail method for new API
474
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
475 # Allows you to add attachments to an email, like so:
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
476 #
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
477 # mail.attachments['filename.jpg'] = File.read('/path/to/filename.jpg')
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
478 #
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
479 # If you do this, then Mail will take the file name and work out the mime type
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
480 # set the Content-Type, Content-Disposition, Content-Transfer-Encoding and
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
481 # base64 encode the contents of the attachment all for you.
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
482 #
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
483 # You can also specify overrides if you want by passing a hash instead of a string:
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
484 #
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
485 # mail.attachments['filename.jpg'] = {:mime_type => 'application/x-gzip',
486 # :content => File.read('/path/to/filename.jpg')}
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
487 #
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
488 # If you want to use a different encoding than Base64, you can pass an encoding in,
489 # but then it is up to you to pass in the content pre-encoded, and don't expect
490 # Mail to know how to decode this data:
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
491 #
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
492 # file_content = SpecialEncode(File.read('/path/to/filename.jpg'))
493 # mail.attachments['filename.jpg'] = {:mime_type => 'application/x-gzip',
494 # :encoding => 'SpecialEncoding',
495 # :content => file_content }
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
496 #
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
497 # You can also search for specific attachments:
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
498 #
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
499 # # By Filename
500 # mail.attachments['filename.jpg'] #=> Mail::Part object or nil
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
501 #
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
502 # # or by index
503 # mail.attachments[0] #=> Mail::Part (first attachment)
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
504 #
7409b734 » José Valim and Mikel Lindsaar
2010-01-24 Some refactoring.
505 def attachments
506 @_message.attachments
507 end
dcb92536 » José Valim and Mikel Lindsaar
2010-01-22 Add basic template rendering to new DSL.
508
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
509 # The main method that creates the message and renders the email templates. There are
510 # two ways to call this method, with a block, or without a block.
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
511 #
65899765 » José Valim and Mikel Lindsaar
2010-01-26 Remove old files, add some information to docs and improve test suite.
512 # Both methods accept a headers hash. This hash allows you to specify the most used headers
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
513 # in an email message, these are:
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
514 #
058f7fea » mikel
2010-05-02 Cleaning up Action Mailer spelling with and without the space
515 # * <tt>:subject</tt> - The subject of the message, if this is omitted, Action Mailer will
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
516 # ask the Rails I18n class for a translated <tt>:subject</tt> in the scope of
517 # <tt>[:actionmailer, mailer_scope, action_name]</tt> or if this is missing, will translate the
518 # humanized version of the <tt>action_name</tt>
519 # * <tt>:to</tt> - Who the message is destined for, can be a string of addresses, or an array
520 # of addresses.
0b05acd4 » mikel
2010-01-26 Implementing class level :defaults hash, instead of delivers_from et al
521 # * <tt>:from</tt> - Who the message is from
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
522 # * <tt>:cc</tt> - Who you would like to Carbon-Copy on this email, can be a string of addresses,
523 # or an array of addresses.
524 # * <tt>:bcc</tt> - Who you would like to Blind-Carbon-Copy on this email, can be a string of
525 # addresses, or an array of addresses.
526 # * <tt>:reply_to</tt> - Who to set the Reply-To header of the email to.
527 # * <tt>:date</tt> - The date to say the email was sent on.
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
528 #
529 # You can set default values for any of the above headers (except :date) by using the <tt>default</tt>
0b05acd4 » mikel
2010-01-26 Implementing class level :defaults hash, instead of delivers_from et al
530 # class method:
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
531 #
9dd65c36 » José Valim and Mikel Lindsaar
2010-01-26 Make defaults accept a hash.
532 # class Notifier < ActionMailer::Base
452bb1e4 » jeremy
2010-01-27 Rename 'defaults' class method to 'default' to reflect that it's a de…
533 # self.default :from => 'no-reply@test.lindsaar.net',
534 # :bcc => 'email_logger@test.lindsaar.net',
535 # :reply_to => 'bounces@test.lindsaar.net'
0b05acd4 » mikel
2010-01-26 Implementing class level :defaults hash, instead of delivers_from et al
536 # end
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
537 #
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
538 # If you need other headers not listed above, use the <tt>headers['name'] = value</tt> method.
539 #
65899765 » José Valim and Mikel Lindsaar
2010-01-26 Remove old files, add some information to docs and improve test suite.
540 # When a <tt>:return_path</tt> is specified as header, that value will be used as the 'envelope from'
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
541 # address for the Mail message. Setting this is useful when you want delivery notifications
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
542 # sent to a different address than the one in <tt>:from</tt>. Mail will actually use the
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
543 # <tt>:return_path</tt> in preference to the <tt>:sender</tt> in preference to the <tt>:from</tt>
544 # field for the 'envelope from' value.
545 #
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
546 # If you do not pass a block to the +mail+ method, it will find all templates in the
be35a151 » josevalim
2010-02-19 Allow to choose the template path and template name used in implicit …
547 # view paths using by default the mailer name and the method name that it is being
548 # called from, it will then create parts for each of these templates intelligently,
549 # making educated guesses on correct content type and sequence, and return a fully
550 # prepared Mail::Message ready to call <tt>:deliver</tt> on to send.
551 #
552 # For example:
553 #
554 # class Notifier < ActionMailer::Base
555 # default :from => 'no-reply@test.lindsaar.net',
556 #
557 # def welcome
558 # mail(:to => 'mikel@test.lindsaar.net')
559 # end
560 # end
561 #
562 # Will look for all templates at "app/views/notifier" with name "welcome". However, those
563 # can be customized:
564 #
565 # mail(:template_path => 'notifications', :template_name => 'another')
566 #
567 # And now it will look for all templates at "app/views/notifications" with name "another".
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
568 #
569 # If you do pass a block, you can render specific templates of your choice:
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
570 #
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
571 # mail(:to => 'mikel@test.lindsaar.net') do |format|
572 # format.text
573 # format.html
574 # end
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
575 #
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
576 # You can even render text directly without using a template:
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
577 #
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
578 # mail(:to => 'mikel@test.lindsaar.net') do |format|
579 # format.text { render :text => "Hello Mikel!" }
580 # format.html { render :text => "<h1>Hello Mikel!</h1>" }
581 # end
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
582 #
74a5889a » José Valim and Mikel Lindsaar
2010-01-26 Refactor content type setting, added tests to ensure boundary exists …
583 # Which will render a <tt>multipart/alternative</tt> email with <tt>text/plain</tt> and
4a6eba32 » José Valim and Mikel Lindsaar
2010-01-25 Added initial documentation for the new API
584 # <tt>text/html</tt> parts.
65899765 » José Valim and Mikel Lindsaar
2010-01-26 Remove old files, add some information to docs and improve test suite.
585 #
586 # The block syntax also allows you to customize the part headers if desired:
587 #
588 # mail(:to => 'mikel@test.lindsaar.net') do |format|
589 # format.text(:content_transfer_encoding => "base64")
590 # format.html
591 # end
592 #
7409b734 » José Valim and Mikel Lindsaar
2010-01-24 Some refactoring.
593 def mail(headers={}, &block)
594 # Guard flag to prevent both the old and the new API from firing
595 # Should be removed when old API is removed
596 @mail_was_called = true
597 m = @_message
258ca148 » José Valim and Mikel Lindsaar
2010-01-24 Delegated ActionMailer::Base.deliveries to Mail.deliveries, added cal…
598
9dd65c36 » José Valim and Mikel Lindsaar
2010-01-26 Make defaults accept a hash.
599 # At the beginning, do not consider class default for parts order neither content_type
600 content_type = headers[:content_type]
601 parts_order = headers[:parts_order]
1cd55928 » José Valim and Mikel Lindsaar
2010-01-22 First work on implicit multipart.
602
08b07b60 » mikel
2010-05-02 Adding ability to pass proc's to the ActionMailer class default method
603 # Call all the procs (if any)
604 default_values = self.class.default.merge(self.class.default) do |k,v|
ceaa100e » mikel
2010-05-02 Adding ability for the procs to be called within the instance, allows…
605 v.respond_to?(:call) ? v.bind(self).call : v
08b07b60 » mikel
2010-05-02 Adding ability to pass proc's to the ActionMailer class default method
606 end
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
607
b5f9a9fc » josevalim
2010-04-12 Move set_fields! to the old API module.
608 # Handle defaults
08b07b60 » mikel
2010-05-02 Adding ability to pass proc's to the ActionMailer class default method
609 headers = headers.reverse_merge(default_values)
9dd65c36 » José Valim and Mikel Lindsaar
2010-01-26 Make defaults accept a hash.
610 headers[:subject] ||= default_i18n_subject
b5f9a9fc » josevalim
2010-04-12 Move set_fields! to the old API module.
611
612 # Apply charset at the beginning so all fields are properly quoted
613 m.charset = charset = headers[:charset]
614
615 # Set configure delivery behavior
616 wrap_delivery_behavior!(headers.delete(:delivery_method))
617
618 # Assign all headers except parts_order, content_type and body
b4fd5e6f » josevalim
2010-04-13 template_name and template_path should not be added to mail headers.
619 assignable = headers.except(:parts_order, :content_type, :body, :template_name, :template_path)
b5f9a9fc » josevalim
2010-04-12 Move set_fields! to the old API module.
620 assignable.each { |k, v| m[k] = v }
951397b4 » José Valim and Mikel Lindsaar
2010-01-22 Get implicit multipart and attachments working together.
621
7409b734 » José Valim and Mikel Lindsaar
2010-01-24 Some refactoring.
622 # Render the templates and blocks
39a1b06f » José Valim and Mikel Lindsaar
2010-01-26 Deprecate old defaults API.
623 responses, explicit_order = collect_responses_and_parts_order(headers, &block)
b5f9a9fc » josevalim
2010-04-12 Move set_fields! to the old API module.
624 create_parts_from_responses(m, responses)
7409b734 » José Valim and Mikel Lindsaar
2010-01-24 Some refactoring.
625
b5f9a9fc » josevalim
2010-04-12 Move set_fields! to the old API module.
626 # Setup content type, reapply charset and handle parts order
9dd65c36 » José Valim and Mikel Lindsaar
2010-01-26 Make defaults accept a hash.
627 m.content_type = set_content_type(m, content_type, headers[:content_type])
951397b4 » José Valim and Mikel Lindsaar
2010-01-22 Get implicit multipart and attachments working together.
628 m.charset = charset
629
e7e4ed48 » José Valim and Mikel Lindsaar
2010-01-24 Set sort order for explicit parts from the collector's template sequence
630 if m.multipart?
9dd65c36 » José Valim and Mikel Lindsaar
2010-01-26 Make defaults accept a hash.
631 parts_order ||= explicit_order || headers[:parts_order]
632 m.body.set_sort_order(parts_order)
951397b4 » José Valim and Mikel Lindsaar
2010-01-22 Get implicit multipart and attachments working together.
633 m.body.sort_parts!
634 end
bb9d71ff » José Valim and Mikel Lindsaar
2010-01-22 Move class methods to deprecated stuff.
635
c34cfcc2 » mikel
2010-01-20 Created mail method for new API
636 m
637 end
638
6ba94460 » José Valim and Mikel Lindsaar
2010-01-23 Make implicit and explicit templates pass through the same part creat…
639 protected
640
9dd65c36 » José Valim and Mikel Lindsaar
2010-01-26 Make defaults accept a hash.
641 def set_content_type(m, user_content_type, class_default)
74a5889a » José Valim and Mikel Lindsaar
2010-01-26 Refactor content type setting, added tests to ensure boundary exists …
642 params = m.content_type_parameters || {}
643 case
644 when user_content_type.present?
645 user_content_type
646 when m.has_attachments?
311d99ee » mikel
2010-06-07 Adding inline attachment support to ActionMailer
647 if m.attachments.detect { |a| a.inline? }
648 ["multipart", "related", params]
649 else
650 ["multipart", "mixed", params]
651 end
74a5889a » José Valim and Mikel Lindsaar
2010-01-26 Refactor content type setting, added tests to ensure boundary exists …
652 when m.multipart?
653 ["multipart", "alternative", params]
654 else
b6b3db67 » mikel
2010-01-28 Fixed bug on HTML only emails getting set to text/plain
655 m.content_type || class_default
74a5889a » José Valim and Mikel Lindsaar
2010-01-26 Refactor content type setting, added tests to ensure boundary exists …
656 end
657 end
658
9dd65c36 » José Valim and Mikel Lindsaar
2010-01-26 Make defaults accept a hash.
659 def default_i18n_subject #:nodoc:
5c3ef8c1 » José Valim and Mikel Lindsaar
2010-01-23 Refactor subject with i18n.
660 mailer_scope = self.class.mailer_name.gsub('/', '.')
30eaecb3 » josevalim
2010-06-12 subject is automatically looked up on I18n using mailer_name and acti…
661 I18n.t(:subject, :scope => [mailer_scope, action_name], :default => action_name.humanize)
5c3ef8c1 » José Valim and Mikel Lindsaar
2010-01-23 Refactor subject with i18n.
662 end
663
39a1b06f » José Valim and Mikel Lindsaar
2010-01-26 Deprecate old defaults API.
664 def collect_responses_and_parts_order(headers) #:nodoc:
665 responses, parts_order = [], nil
7409b734 » José Valim and Mikel Lindsaar
2010-01-24 Some refactoring.
666
667 if block_given?
a09e9925 » josevalim
2010-03-27 Ensure details are frozen after @details_keys lookup. The implementat…
668 collector = ActionMailer::Collector.new(lookup_context) { render(action_name) }
7409b734 » José Valim and Mikel Lindsaar
2010-01-24 Some refactoring.
669 yield(collector)
39a1b06f » José Valim and Mikel Lindsaar
2010-01-26 Deprecate old defaults API.
670 parts_order = collector.responses.map { |r| r[:content_type] }
7409b734 » José Valim and Mikel Lindsaar
2010-01-24 Some refactoring.
671 responses = collector.responses
672 elsif headers[:body]
673 responses << {
be35a151 » josevalim
2010-02-19 Allow to choose the template path and template name used in implicit …
674 :body => headers.delete(:body),
452bb1e4 » jeremy
2010-01-27 Rename 'defaults' class method to 'default' to reflect that it's a de…
675 :content_type => self.class.default[:content_type] || "text/plain"
7409b734 » José Valim and Mikel Lindsaar
2010-01-24 Some refactoring.
676 }
677 else
be35a151 » josevalim
2010-02-19 Allow to choose the template path and template name used in implicit …
678 templates_path = headers.delete(:template_path) || self.class.mailer_name
679 templates_name = headers.delete(:template_name) || action_name
680
681 each_template(templates_path, templates_name) do |template|
f28d856c » josevalim
2010-03-19 Improve performance of the rendering stack by freezing formats as a s…
682 self.formats = template.formats
683
7409b734 » José Valim and Mikel Lindsaar
2010-01-24 Some refactoring.
684 responses << {
2a126868 » josevalim
2010-03-12 Allow anything that responds to render to be given as :template and u…
685 :body => render(:template => template),
7409b734 » José Valim and Mikel Lindsaar
2010-01-24 Some refactoring.
686 :content_type => template.mime_type.to_s
687 }
688 end
689 end
690
39a1b06f » José Valim and Mikel Lindsaar
2010-01-26 Deprecate old defaults API.
691 [responses, parts_order]
7409b734 » José Valim and Mikel Lindsaar
2010-01-24 Some refactoring.
692 end
693
be35a151 » josevalim
2010-02-19 Allow to choose the template path and template name used in implicit …
694 def each_template(paths, name, &block) #:nodoc:
41af6d9a » jeremy
2010-03-17 Use Array.wrap not Array()
695 Array.wrap(paths).each do |path|
36eb1a68 » josevalim
2010-03-08 Bring AM up to date with new rendering stack.
696 templates = lookup_context.find_all(name, path)
00d6271d » josevalim
2010-03-09 Clean up the API required from ActionView::Template.
697 templates = templates.uniq_by { |t| t.formats }
0ece244f » José Valim and Mikel Lindsaar
2010-01-24 Ensure implicit multipart templates with locale works as expected.
698
36eb1a68 » josevalim
2010-03-08 Bring AM up to date with new rendering stack.
699 unless templates.empty?
700 templates.each(&block)
701 return
99f960a3 » José Valim and Mikel Lindsaar
2010-01-24 Handle some TODOs and deprecations.
702 end
703 end
704 end
705
b5f9a9fc » josevalim
2010-04-12 Move set_fields! to the old API module.
706 def create_parts_from_responses(m, responses) #:nodoc:
6ba94460 » José Valim and Mikel Lindsaar
2010-01-23 Make implicit and explicit templates pass through the same part creat…
707 if responses.size == 1 && !m.has_attachments?
9dd65c36 » José Valim and Mikel Lindsaar
2010-01-26 Make defaults accept a hash.
708 responses[0].each { |k,v| m[k] = v }
74a5889a » José Valim and Mikel Lindsaar
2010-01-26 Refactor content type setting, added tests to ensure boundary exists …
709 elsif responses.size > 1 && m.has_attachments?
6ba94460 » José Valim and Mikel Lindsaar
2010-01-23 Make implicit and explicit templates pass through the same part creat…
710 container = Mail::Part.new
74a5889a » José Valim and Mikel Lindsaar
2010-01-26 Refactor content type setting, added tests to ensure boundary exists …
711 container.content_type = "multipart/alternative"
b5f9a9fc » josevalim
2010-04-12 Move set_fields! to the old API module.
712 responses.each { |r| insert_part(container, r, m.charset) }
6ba94460 » José Valim and Mikel Lindsaar
2010-01-23 Make implicit and explicit templates pass through the same part creat…
713 m.add_part(container)
714 else
b5f9a9fc » josevalim
2010-04-12 Move set_fields! to the old API module.
715 responses.each { |r| insert_part(m, r, m.charset) }
6ba94460 » José Valim and Mikel Lindsaar
2010-01-23 Make implicit and explicit templates pass through the same part creat…
716 end
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
717 end
718
6ba94460 » José Valim and Mikel Lindsaar
2010-01-23 Make implicit and explicit templates pass through the same part creat…
719 def insert_part(container, response, charset) #:nodoc:
720 response[:charset] ||= charset
721 part = Mail::Part.new(response)
722 container.add_part(part)
359caef3 » jamis
2005-05-29 A very thorough refactoring, resulting in new mail property setters a…
723 end
3fad0cd0 » dhh
2005-02-19 Added support for charsets for both subject and body. The default cha…
724
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
725 module DeprecatedUrlOptions
726 def default_url_options
727 deprecated_url_options
728 end
729
730 def default_url_options=(val)
731 deprecated_url_options
732 end
733
734 def deprecated_url_options
735 raise "You can no longer call ActionMailer::Base.default_url_options " \
736 "directly. You need to set config.action_mailer.default_url_options. " \
737 "If you are using ActionMailer standalone, you need to include the " \
738 "url_helpers of a router directly."
739 end
740 end
741
742 # This module will complain if the user tries to set default_url_options
f17159b0 » fxn
2010-06-14 edit pass: the names of Rails components have a space, ie, "Active Re…
743 # directly instead of through the config object. In Action Mailer's Railtie,
458f5712 » wycats
2010-05-15 Remove the need for a special action_mailer.url_for initializer that …
744 # we include the url_helpers of the router, which will override this module
745 extend DeprecatedUrlOptions
746
ef5dadaf » nex3
2010-04-27 Only run load hooks once a file has been fully loaded.
747 ActiveSupport.run_load_hooks(:action_mailer, self)
db045dbb » dhh
2004-11-24 Initial
748 end
749 end
Something went wrong with that request. Please try again.