Skip to content
Newer
Older
100644 797 lines (748 sloc) 33.6 KB
616ebb8 @josevalim Remove unused code paths and require mail only when it's needed.
josevalim authored Dec 28, 2009
1 require 'mail'
34b23e7 @spastorino Action Mailer async flag is true by default using a Synchronous impl
spastorino authored Sep 10, 2012
2 require 'action_mailer/queued_message'
c985a0e Add some tests to collector with templates and any.
José Valim and Mikel Lindsaar authored Jan 23, 2010
3 require 'action_mailer/collector'
284ca81 @joshk remove AM delegating register_observer and register_interceptor to Ma…
joshk authored Apr 2, 2011
4 require 'active_support/core_ext/string/inflections'
0f8a6eb @sikachu Fix missing requires in Action Mailer
sikachu authored Apr 14, 2011
5 require 'active_support/core_ext/hash/except'
c17d200 @lest mailer can be anonymous
lest authored May 13, 2012
6 require 'active_support/core_ext/module/anonymous'
2a30150 @jeremy Use synchronous queue by default. Separate queued message delivery jo…
jeremy authored Sep 16, 2012
7 require 'active_support/queueing'
6788db8 @josevalim Move Rails::LogSubscriber to ActiveSupport::LogSubscriber, allowing f…
josevalim authored Jun 24, 2010
8 require 'action_mailer/log_subscriber'
a63caa4 Get tests to run (with failures) without old base around
Yehuda Katz + Carl Lerche authored Jun 15, 2009
9
7c0e3b8 @vijaydev remove nodoc [ci skip]
vijaydev authored Sep 21, 2012
10 module ActionMailer
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
11 # Action Mailer allows you to send email from your application using a mailer model and views.
db045db @dhh Initial
dhh authored Nov 24, 2004
12 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
13 # = Mailer Models
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
14 #
98dc582 @lifo Merge docrails.
lifo authored May 25, 2008
15 # To use Action Mailer, you need to create a mailer model.
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
16 #
f44a0b1 @romdi fix usage examples and more to use new invocations
romdi authored Feb 6, 2010
17 # $ rails generate mailer Notifier
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
18 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
19 # The generated model inherits from <tt>ActionMailer::Base</tt>. A mailer model defines methods
20 # used to generate an email message. In these methods, you can setup variables to be used in
21 # the mailer views, options on the mail itself such as the <tt>:from</tt> address, and attachments.
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
22 #
23 # Examples:
24 #
0f0213f @siong1987 minor spacing fix in code example in ActionMailer::Base.
siong1987 authored May 28, 2011
25 # class Notifier < ActionMailer::Base
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
26 # default :from => 'no-reply@example.com',
27 # :return_path => 'system@example.com'
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
28 #
0f0213f @siong1987 minor spacing fix in code example in ActionMailer::Base.
siong1987 authored May 28, 2011
29 # def welcome(recipient)
30 # @account = recipient
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
31 # mail(:to => recipient.email_address_with_name,
32 # :bcc => ["bcc@example.com", "Order Watcher <watcher@example.com>"])
0f0213f @siong1987 minor spacing fix in code example in ActionMailer::Base.
siong1987 authored May 28, 2011
33 # end
34 # end
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
35 #
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
36 # Within the mailer method, you have access to the following methods:
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
37 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
38 # * <tt>attachments[]=</tt> - Allows you to add attachments to your email in an intuitive
39 # manner; <tt>attachments['filename.png'] = File.read('path/to/filename.png')</tt>
6589976 Remove old files, add some information to docs and improve test suite.
José Valim and Mikel Lindsaar authored Jan 26, 2010
40 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
41 # * <tt>attachments.inline[]=</tt> - Allows you to add an inline attachment to your email
42 # in the same manner as <tt>attachments[]=</tt>
3762362 @mikel Updating readme for ActionMailer::Base
mikel authored Jun 7, 2010
43 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
44 # * <tt>headers[]=</tt> - Allows you to specify any header field in your email such
45 # as <tt>headers['X-No-Spam'] = 'True'</tt>. Note, while most fields like <tt>To:</tt>
46 # <tt>From:</tt> can only appear once in an email header, other fields like <tt>X-Anything</tt>
47 # can appear multiple times. If you want to change a field that can appear multiple times,
48 # you need to set it to nil first so that Mail knows you are replacing it and not adding
daad445 itsy bitsy changes to ActionMailer documentation
Neeraj Singh authored Jul 28, 2010
49 # another field of the same name.
6589976 Remove old files, add some information to docs and improve test suite.
José Valim and Mikel Lindsaar authored Jan 26, 2010
50 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
51 # * <tt>headers(hash)</tt> - Allows you to specify multiple headers in your email such
52 # as <tt>headers({'X-No-Spam' => 'True', 'In-Reply-To' => '1234@message.id'})</tt>
9520166 @mikel Fixed up being able to pass random headers in with headers, or mail. …
mikel authored Jan 27, 2010
53 #
daad445 itsy bitsy changes to ActionMailer documentation
Neeraj Singh authored Jul 29, 2010
54 # * <tt>mail</tt> - Allows you to specify email to be sent.
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
55 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
56 # The hash passed to the mail method allows you to specify any header that a Mail::Message
57 # will accept (any valid Email header including optional fields).
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
58 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
59 # The mail method, if not passed a block, will inspect your views and send all the views with
60 # the same name as the method, so the above action would send the +welcome.text.erb+ view
61 # file as well as the +welcome.text.html.erb+ view file in a +multipart/alternative+ email.
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
62 #
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
63 # If you want to explicitly render only certain templates, pass a block:
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
64 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
65 # mail(:to => user.email) do |format|
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
66 # format.text
67 # format.html
68 # end
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
69 #
daad445 itsy bitsy changes to ActionMailer documentation
Neeraj Singh authored Jul 29, 2010
70 # The block syntax is also useful in providing information specific to a part:
6589976 Remove old files, add some information to docs and improve test suite.
José Valim and Mikel Lindsaar authored Jan 26, 2010
71 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
72 # mail(:to => user.email) do |format|
73 # format.text(:content_transfer_encoding => "base64")
6589976 Remove old files, add some information to docs and improve test suite.
José Valim and Mikel Lindsaar authored Jan 26, 2010
74 # format.html
75 # end
76 #
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
77 # Or even to render a special view:
6589976 Remove old files, add some information to docs and improve test suite.
José Valim and Mikel Lindsaar authored Jan 26, 2010
78 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
79 # mail(:to => user.email) do |format|
6589976 Remove old files, add some information to docs and improve test suite.
José Valim and Mikel Lindsaar authored Jan 26, 2010
80 # format.text
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
81 # format.html { render "some_other_template" }
6589976 Remove old files, add some information to docs and improve test suite.
José Valim and Mikel Lindsaar authored Jan 26, 2010
82 # end
83 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
84 # = Mailer views
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
85 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
86 # Like Action Controller, each mailer class has a corresponding view directory in which each
87 # method of the class looks for a template with its name.
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
88 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
89 # To define a template to be used with a mailing, create an <tt>.erb</tt> file with the same
90 # name as the method in your mailer model. For example, in the mailer defined above, the template at
91 # <tt>app/views/notifier/welcome.text.erb</tt> would be used to generate the email.
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
92 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
93 # Variables defined in the model are accessible as instance variables in the view.
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
94 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
95 # Emails by default are sent in plain text, so a sample view for our model example might look like this:
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
96 #
97 # Hi <%= @account.name %>,
98 # Thanks for joining our service! Please check back often.
99 #
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
100 # You can even use Action Pack helpers in these views. For example:
101 #
102 # You got a new note!
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
103 # <%= truncate(@note.body, :length => 25) %>
ee70d1b @josevalim adv_attr_accessors in ActionMailer are not sent to the views, use the…
josevalim authored Dec 25, 2009
104 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
105 # If you need to access the subject, from or the recipients in the view, you can do that through message object:
ee70d1b @josevalim adv_attr_accessors in ActionMailer are not sent to the views, use the…
josevalim authored Dec 25, 2009
106 #
6589976 Remove old files, add some information to docs and improve test suite.
José Valim and Mikel Lindsaar authored Jan 26, 2010
107 # You got a new note from <%= message.from %>!
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
108 # <%= truncate(@note.body, :length => 25) %>
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
109 #
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
110 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
111 # = Generating URLs
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
112 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
113 # URLs can be generated in mailer views using <tt>url_for</tt> or named routes. Unlike controllers from
114 # Action Pack, the mailer instance doesn't have any context about the incoming request, so you'll need
115 # to provide all of the details needed to generate a URL.
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
116 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
117 # When using <tt>url_for</tt> you'll need to provide the <tt>:host</tt>, <tt>:controller</tt>, and <tt>:action</tt>:
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
118 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
119 # <%= url_for(:host => "example.com", :controller => "welcome", :action => "greeting") %>
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
120 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored Apr 21, 2008
121 # When using named routes you only need to supply the <tt>:host</tt>:
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
122 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
123 # <%= users_url(:host => "example.com") %>
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored Apr 21, 2008
124 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
125 # You should use the <tt>named_route_url</tt> style (which generates absolute URLs) and avoid using the
126 # <tt>named_route_path</tt> style (which generates relative URLs), since clients reading the mail will
127 # have no concept of a current URL from which to determine a relative path.
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored Apr 21, 2008
128 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
129 # It is also possible to set a default host that will be used in all mailers by setting the <tt>:host</tt>
130 # option as a configuration option in <tt>config/application.rb</tt>:
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored Apr 21, 2008
131 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
132 # config.action_mailer.default_url_options = { :host => "example.com" }
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
133 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
134 # When you decide to set a default <tt>:host</tt> for your mailers, then you need to make sure to use the
135 # <tt>:only_path => false</tt> option when using <tt>url_for</tt>. Since the <tt>url_for</tt> view helper
136 # will generate relative URLs by default when a <tt>:host</tt> option isn't explicitly provided, passing
137 # <tt>:only_path => false</tt> will ensure that absolute URLs are generated.
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
138 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
139 # = Sending mail
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
140 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
141 # Once a mailer action and template are defined, you can deliver your message or create it and save it
142 # for delivery later:
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
143 #
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
144 # Notifier.welcome(david).deliver # sends the email
7e0cf56 @jonleighton Support `Mailer.deliver_foo(*args)` as a synonym for `Mailer.foo(*arg…
jonleighton authored Sep 28, 2012
145 # Notifier.deliver_welcome(david) # synonym for the former
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
146 # mail = Notifier.welcome(david) # => a Mail::Message object
147 # mail.deliver # sends the email
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
148 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
149 # You never instantiate your mailer class. Rather, you just call the method you defined on the class itself.
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
150 #
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
151 # = Multipart Emails
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
152 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
153 # Multipart messages can also be used implicitly because Action Mailer will automatically detect and use
154 # multipart templates, where each template is named after the name of the action, followed by the content
155 # type. Each such detected template will be added as a separate part to the message.
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
156 #
daad445 itsy bitsy changes to ActionMailer documentation
Neeraj Singh authored Jul 29, 2010
157 # For example, if the following templates exist:
b62c549 @jasonfox The name for the plain text template in Rails3 appears to be method.t…
jasonfox authored Jun 15, 2011
158 # * signup_notification.text.erb
21187c0 @dhh Apply the rest of Chads patch
dhh authored Feb 21, 2007
159 # * signup_notification.text.html.erb
160 # * signup_notification.text.xml.builder
6589976 Remove old files, add some information to docs and improve test suite.
José Valim and Mikel Lindsaar authored Jan 26, 2010
161 # * signup_notification.text.yaml.erb
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
162 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
163 # Each would be rendered and added as a separate part to the message, with the corresponding content
164 # type. The content type for the entire message is automatically set to <tt>multipart/alternative</tt>,
165 # which indicates that the email contains multiple different representations of the same email
166 # body. The same instance variables defined in the action are passed to all email templates.
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored May 29, 2005
167 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
168 # Implicit template rendering is not performed if any attachments or parts have been added to the email.
169 # This means that you'll have to manually add each part to the email and set the content type of the email
170 # to <tt>multipart/alternative</tt>.
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
171 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
172 # = Attachments
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
173 #
daad445 itsy bitsy changes to ActionMailer documentation
Neeraj Singh authored Jul 29, 2010
174 # Sending attachment in emails is easy:
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, …
Marcel Molina authored May 10, 2006
175 #
176 # class ApplicationMailer < ActionMailer::Base
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
177 # def welcome(recipient)
3762362 @mikel Updating readme for ActionMailer::Base
mikel authored Jun 8, 2010
178 # attachments['free_book.pdf'] = File.read('path/to/file.pdf')
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
179 # mail(:to => recipient, :subject => "New account information")
db045db @dhh Initial
dhh authored Nov 24, 2004
180 # end
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Infl…
josh authored May 14, 2008
181 # end
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
182 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
183 # Which will (if it had both a <tt>welcome.text.erb</tt> and <tt>welcome.text.html.erb</tt>
184 # template in the view directory), send a complete <tt>multipart/mixed</tt> email with two parts,
185 # the first part being a <tt>multipart/alternative</tt> with the text and HTML email parts inside,
186 # and the second being a <tt>application/pdf</tt> with a Base64 encoded copy of the file.pdf book
187 # with the filename +free_book.pdf+.
c927aa0 @dhh Updated documentation
dhh authored Dec 16, 2004
188 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
189 # If you need to send attachments with no content, you need to create an empty view for it,
190 # or add an empty body parameter like this:
45b1045 @dmathieu raise an error if no implicit mailer template could be found
dmathieu authored Jun 20, 2012
191 #
192 # class ApplicationMailer < ActionMailer::Base
193 # def welcome(recipient)
194 # attachments['free_book.pdf'] = File.read('path/to/file.pdf')
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
195 # mail(:to => recipient, :subject => "New account information", :body => "")
45b1045 @dmathieu raise an error if no implicit mailer template could be found
dmathieu authored Jun 20, 2012
196 # end
197 # end
198 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
199 # = Inline Attachments
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored Aug 14, 2010
200 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
201 # You can also specify that a file should be displayed inline with other HTML. This is useful
202 # if you want to display a corporate logo or a photo.
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored Aug 14, 2010
203 #
3762362 @mikel Updating readme for ActionMailer::Base
mikel authored Jun 8, 2010
204 # class ApplicationMailer < ActionMailer::Base
205 # def welcome(recipient)
206 # attachments.inline['photo.png'] = File.read('path/to/photo.png')
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
207 # mail(:to => recipient, :subject => "Here is what we look like")
3762362 @mikel Updating readme for ActionMailer::Base
mikel authored Jun 8, 2010
208 # end
209 # end
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored Aug 14, 2010
210 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
211 # And then to reference the image in the view, you create a <tt>welcome.html.erb</tt> file and
212 # make a call to +image_tag+ passing in the attachment you want to display and then call
213 # +url+ on the attachment to get the relative content id path for the image source:
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored Aug 14, 2010
214 #
3762362 @mikel Updating readme for ActionMailer::Base
mikel authored Jun 8, 2010
215 # <h1>Please Don't Cringe</h1>
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored Aug 14, 2010
216 #
3762362 @mikel Updating readme for ActionMailer::Base
mikel authored Jun 8, 2010
217 # <%= image_tag attachments['photo.png'].url -%>
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored Aug 14, 2010
218 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
219 # As we are using Action View's +image_tag+ method, you can pass in any other options you want:
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored Aug 14, 2010
220 #
3762362 @mikel Updating readme for ActionMailer::Base
mikel authored Jun 8, 2010
221 # <h1>Please Don't Cringe</h1>
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored Aug 14, 2010
222 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
223 # <%= image_tag attachments['photo.png'].url, :alt => 'Our Photo', :class => 'photo' -%>
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored Aug 14, 2010
224 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
225 # = Observing and Intercepting Mails
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
226 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
227 # Action Mailer provides hooks into the Mail observer and interceptor methods. These allow you to
228 # register classes that are called during the mail delivery life cycle.
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
229 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
230 # An observer class must implement the <tt>:delivered_email(message)</tt> method which will be
231 # called once for every email sent after the email has been sent.
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
232 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
233 # An interceptor class must implement the <tt>:delivering_email(message)</tt> method which will be
234 # called before the email is sent, allowing you to make modifications to the email before it hits
235 # the delivery agents. Your class should make any needed modifications directly to the passed
236 # in Mail::Message instance.
20bd4bd @dhh Updated docs and otherwise
dhh authored Sep 2, 2006
237 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
238 # = Default Hash
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
239 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
240 # Action Mailer provides some intelligent defaults for your emails, these are usually specified in a
241 # default method inside the class definition:
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
242 #
fb30feb @mikel Adding more docs to ActionMailer
mikel authored May 2, 2010
243 # class Notifier < ActionMailer::Base
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
244 # default :sender => 'system@example.com'
fb30feb @mikel Adding more docs to ActionMailer
mikel authored May 2, 2010
245 # end
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
246 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
247 # You can pass in any header value that a <tt>Mail::Message</tt> accepts. Out of the box,
248 # <tt>ActionMailer::Base</tt> sets the following:
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
249 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
250 # * <tt>:mime_version => "1.0"</tt>
251 # * <tt>:charset => "UTF-8",</tt>
252 # * <tt>:content_type => "text/plain",</tt>
253 # * <tt>:parts_order => [ "text/plain", "text/enriched", "text/html" ]</tt>
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
254 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
255 # <tt>parts_order</tt> and <tt>charset</tt> are not actually valid <tt>Mail::Message</tt> header fields,
256 # but Action Mailer translates them appropriately and sets the correct values.
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
257 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
258 # As you can pass in any header, you need to either quote the header as a string, or pass it in as
259 # an underscored symbol, so the following will work:
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
260 #
fb30feb @mikel Adding more docs to ActionMailer
mikel authored May 2, 2010
261 # class Notifier < ActionMailer::Base
262 # default 'Content-Transfer-Encoding' => '7bit',
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
263 # :content_description => 'This is a description'
fb30feb @mikel Adding more docs to ActionMailer
mikel authored May 2, 2010
264 # end
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
265 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
266 # Finally, Action Mailer also supports passing <tt>Proc</tt> objects into the default hash, so you
267 # can define methods that evaluate as the message is being generated:
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
268 #
fb30feb @mikel Adding more docs to ActionMailer
mikel authored May 2, 2010
269 # class Notifier < ActionMailer::Base
270 # default 'X-Special-Header' => Proc.new { my_method }
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
271 #
fb30feb @mikel Adding more docs to ActionMailer
mikel authored May 2, 2010
272 # private
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
273 #
fb30feb @mikel Adding more docs to ActionMailer
mikel authored May 2, 2010
274 # def my_method
275 # 'some complex call'
276 # end
277 # end
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
278 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
279 # Note that the proc is evaluated right at the start of the mail message generation, so if you
280 # set something in the defaults using a proc, and then set the same thing inside of your
281 # mailer method, it will get over written by the mailer method.
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
282 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
283 # It is also possible to set these default options that will be used in all mailers through
284 # the <tt>default_options=</tt> configuration in <tt>config/application.rb</tt>:
3009c63 @carlosantoniodasilva Improve docs, changelog and release notes for Action Mailer default_o…
carlosantoniodasilva authored Jul 6, 2012
285 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
286 # config.action_mailer.default_options = { from: "no-reply@example.org" }
3009c63 @carlosantoniodasilva Improve docs, changelog and release notes for Action Mailer default_o…
carlosantoniodasilva authored Jul 7, 2012
287 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
288 # = Callbacks
4f28c4f @jsl Add ability to define callbacks in ActionMailer using AbstractControl…
jsl authored Mar 10, 2012
289 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
290 # You can specify callbacks using before_filter and after_filter for configuring your messages.
291 # This may be useful, for example, when you want to add default inline attachments for all
292 # messages sent out by a certain mailer class:
4f28c4f @jsl Add ability to define callbacks in ActionMailer using AbstractControl…
jsl authored Mar 10, 2012
293 #
294 # class Notifier < ActionMailer::Base
295 # before_filter :add_inline_attachment!
296 #
297 # def welcome
298 # mail
299 # end
300 #
301 # private
302 #
303 # def add_inline_attachment!
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
304 # attachments.inline["footer.jpg"] = File.read('/path/to/filename.jpg')
4f28c4f @jsl Add ability to define callbacks in ActionMailer using AbstractControl…
jsl authored Mar 10, 2012
305 # end
306 # end
307 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
308 # Callbacks in ActionMailer are implemented using AbstractController::Callbacks, so you
309 # can define and configure callbacks in the same manner that you would use callbacks in
310 # classes that inherit from ActionController::Base.
4f28c4f @jsl Add ability to define callbacks in ActionMailer using AbstractControl…
jsl authored Mar 10, 2012
311 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
312 # Note that unless you have a specific reason to do so, you should prefer using before_filter
313 # rather than after_filter in your ActionMailer classes so that headers are parsed properly.
4f28c4f @jsl Add ability to define callbacks in ActionMailer using AbstractControl…
jsl authored Mar 10, 2012
314 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
315 # = Configuration options
c927aa0 @dhh Updated documentation
dhh authored Dec 16, 2004
316 #
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
317 # These options are specified on the class level, like
e968acc @radar Update ActionMailer documentation to not use deprecated template_root…
radar authored Nov 26, 2010
318 # <tt>ActionMailer::Base.raise_delivery_errors = true</tt>
c927aa0 @dhh Updated documentation
dhh authored Dec 16, 2004
319 #
fb30feb @mikel Adding more docs to ActionMailer
mikel authored May 2, 2010
320 # * <tt>default</tt> - You can pass this in at a class level as well as within the class itself as
321 # per the above section.
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
322 #
c927aa0 @dhh Updated documentation
dhh authored Dec 16, 2004
323 # * <tt>logger</tt> - the logger is used for generating information on the mailing run if available.
324 # Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers.
325 #
64092de @fxn Improve documentation coverage and markup
fxn authored May 2, 2008
326 # * <tt>smtp_settings</tt> - Allows detailed configuration for <tt>:smtp</tt> delivery method:
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
327 # * <tt>:address</tt> - Allows you to use a remote mail server. Just change it from its default
328 # "localhost" setting.
dc4eec1 @lifo Merge docrails:
lifo authored May 9, 2008
329 # * <tt>:port</tt> - On the off chance that your mail server doesn't run on port 25, you can change it.
330 # * <tt>:domain</tt> - If you need to specify a HELO domain, you can do it here.
331 # * <tt>:user_name</tt> - If your mail server requires authentication, set the username in this setting.
332 # * <tt>:password</tt> - If your mail server requires authentication, set the password in this setting.
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
333 # * <tt>:authentication</tt> - If your mail server requires authentication, you need to specify the
334 # authentication type here.
5a898e1 Explain actionamailer authentication types
Peter Baker authored Oct 14, 2010
335 # This is a symbol and one of <tt>:plain</tt> (will send the password in the clear), <tt>:login</tt> (will
3457db7 @dalibor Correct spelling for Base64 in action_mailer
dalibor authored Mar 3, 2011
336 # send password Base64 encoded) or <tt>:cram_md5</tt> (combines a Challenge/Response mechanism to exchange
5a898e1 Explain actionamailer authentication types
Peter Baker authored Oct 14, 2010
337 # information and a cryptographic Message Digest 5 algorithm to hash important information)
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
338 # * <tt>:enable_starttls_auto</tt> - When set to true, detects if STARTTLS is enabled in your SMTP server
339 # and starts to use it.
d500ad3 @joshk Removed deprecated ActionMailer API and related tests
joshk authored May 24, 2011
340 # * <tt>:openssl_verify_mode</tt> - When using TLS, you can set how OpenSSL checks the certificate. This is
341 # really useful if you need to validate a self-signed and/or a wildcard certificate. You can use the name
342 # of an OpenSSL verify constant ('none', 'peer', 'client_once','fail_if_no_peer_cert') or directly the
a1639ad @flop Undocumented :openssl_verify_mode option for smtp_settings
flop authored Apr 19, 2011
343 # constant (OpenSSL::SSL::VERIFY_NONE, OpenSSL::SSL::VERIFY_PEER,...).
c927aa0 @dhh Updated documentation
dhh authored Dec 16, 2004
344 #
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored May 16, 2008
345 # * <tt>sendmail_settings</tt> - Allows you to override options for the <tt>:sendmail</tt> delivery method.
346 # * <tt>:location</tt> - The location of the sendmail executable. Defaults to <tt>/usr/sbin/sendmail</tt>.
b72cd29 @mikel Fixing spelling
mikel authored Jan 18, 2011
347 # * <tt>:arguments</tt> - The command line arguments. Defaults to <tt>-i -t</tt> with <tt>-f sender@address</tt>
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
348 # added automatically before the message is sent.
dc4eec1 @lifo Merge docrails:
lifo authored May 9, 2008
349 #
fbe6c3c @edavis10 Adds a :file delivery_method to save email to a file on disk
edavis10 authored Aug 7, 2009
350 # * <tt>file_settings</tt> - Allows you to override options for the <tt>:file</tt> delivery method.
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
351 # * <tt>:location</tt> - The directory into which emails will be written. Defaults to the application
352 # <tt>tmp/mails</tt>.
fbe6c3c @edavis10 Adds a :file delivery_method to save email to a file on disk
edavis10 authored Aug 8, 2009
353 #
dc4eec1 @lifo Merge docrails:
lifo authored May 9, 2008
354 # * <tt>raise_delivery_errors</tt> - Whether or not errors should be raised if the email fails to be delivered.
c927aa0 @dhh Updated documentation
dhh authored Dec 16, 2004
355 #
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
356 # * <tt>delivery_method</tt> - Defines a delivery method. Possible values are <tt>:smtp</tt> (default),
357 # <tt>:sendmail</tt>, <tt>:test</tt>, and <tt>:file</tt>. Or you may provide a custom delivery method
a4726d3 @dmathieu just specify what's to be done, not what's not to be.
dmathieu authored Jun 20, 2012
358 # object e.g. MyOwnDeliveryMethodClass. See the Mail gem documentation on the interface you need to
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
359 # implement for a custom delivery agent.
c927aa0 @dhh Updated documentation
dhh authored Dec 16, 2004
360 #
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
361 # * <tt>perform_deliveries</tt> - Determines whether emails are actually sent from Action Mailer when you
5d0d4d8 @smartinez87 Remove extra white spaces on ActionMailer docs.
smartinez87 authored May 23, 2011
362 # call <tt>.deliver</tt> on an mail message or on an Action Mailer method. This is on by default but can
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
363 # be turned off to aid in functional testing.
c927aa0 @dhh Updated documentation
dhh authored Dec 16, 2004
364 #
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
365 # * <tt>deliveries</tt> - Keeps an array of all the emails sent out through the Action Mailer with
366 # <tt>delivery_method :test</tt>. Most useful for unit and functional testing.
af56c80 @dhh Updated documentation
dhh authored Feb 24, 2005
367 #
3b7947e @vijaydev Merge branch 'master' of github.com:lifo/docrails
vijaydev authored Sep 21, 2012
368 # * <tt>queue</> - The queue that will be used to deliver the mail. The queue should expect a job that responds to <tt>run</tt>.
4964d3b @josevalim Make ActionMailer::Base inherit from AbstractController::Base
josevalim authored Dec 22, 2009
369 class Base < AbstractController::Base
dbcf01e @mikel Removing quoting.rb, upgrade to 2.1.3.6, changing all utf-8 reference…
mikel authored Apr 8, 2010
370 include DeliveryMethods
f30d73b Add new class delivery method API.
José Valim and Mikel Lindsaar authored Jan 24, 2010
371 abstract!
372
c03c40b @josevalim Expose a _render_partial hook as thhe _render_template one and make u…
josevalim authored Dec 31, 2009
373 include AbstractController::Logger
83f4d86 @dhh Rename the RenderingController module to just plain Rendering
dhh authored Dec 20, 2009
374 include AbstractController::Rendering
a9751a7 @josevalim Refactor ActionMailer layout and remove legacy one.
josevalim authored Oct 17, 2009
375 include AbstractController::Layouts
684c2dc @josevalim Remove ActionMailer helpers and rely on AbstractController one.
josevalim authored Oct 18, 2009
376 include AbstractController::Helpers
48a3985 @josevalim Also include translation in ActionMailer.
josevalim authored Jan 26, 2010
377 include AbstractController::Translation
08baa34 @dhh Extract assets paths and make them available to Action Mailer as well
dhh authored Jun 2, 2010
378 include AbstractController::AssetPaths
4f28c4f @jsl Add ability to define callbacks in ActionMailer using AbstractControl…
jsl authored Mar 10, 2012
379 include AbstractController::Callbacks
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored May 29, 2005
380
7d86235 @lest get rid of using instance_variable_names method from AS
lest authored Jan 7, 2012
381 self.protected_instance_variables = [:@_action_has_layout]
d42bb68 @josevalim More updates to ivars list.
josevalim authored May 6, 2011
382
9f2d1a1 @fxn spurious space I saw in passing
fxn authored Sep 18, 2012
383 helper ActionMailer::MailHelper
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
384
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
385 private_class_method :new #:nodoc:
db045db @dhh Initial
dhh authored Nov 24, 2004
386
e5ab4b0 @jeremy Convert to class_attribute
jeremy authored Jan 31, 2010
387 class_attribute :default_params
9dd65c3 Make defaults accept a hash.
José Valim and Mikel Lindsaar authored Jan 26, 2010
388 self.default_params = {
389 :mime_version => "1.0",
dbcf01e @mikel Removing quoting.rb, upgrade to 2.1.3.6, changing all utf-8 reference…
mikel authored Apr 8, 2010
390 :charset => "UTF-8",
9dd65c3 Make defaults accept a hash.
José Valim and Mikel Lindsaar authored Jan 26, 2010
391 :content_type => "text/plain",
392 :parts_order => [ "text/plain", "text/enriched", "text/html" ]
e5ab4b0 @jeremy Convert to class_attribute
jeremy authored Feb 1, 2010
393 }.freeze
e1c1318 Added delivers_from.
José Valim and Mikel Lindsaar authored Jan 25, 2010
394
45537f0 @rafaelfranca Allow users to configure the queue for the mailers
rafaelfranca authored Sep 12, 2012
395 class_attribute :queue
2a30150 @jeremy Use synchronous queue by default. Separate queued message delivery jo…
jeremy authored Sep 17, 2012
396 self.queue = ActiveSupport::SynchronousQueue.new
45537f0 @rafaelfranca Allow users to configure the queue for the mailers
rafaelfranca authored Sep 12, 2012
397
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but …
jamis authored Jul 31, 2005
398 class << self
284ca81 @joshk remove AM delegating register_observer and register_interceptor to Ma…
joshk authored Apr 2, 2011
399 # Register one or more Observers which will be notified when mail is delivered.
400 def register_observers(*observers)
401 observers.flatten.compact.each { |observer| register_observer(observer) }
402 end
403
404 # Register one or more Interceptors which will be called before mail is sent.
405 def register_interceptors(*interceptors)
406 interceptors.flatten.compact.each { |interceptor| register_interceptor(interceptor) }
407 end
408
409 # Register an Observer which will be notified when mail is delivered.
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
410 # Either a class or a string can be passed in as the Observer. If a string is passed in
411 # it will be <tt>constantize</tt>d.
284ca81 @joshk remove AM delegating register_observer and register_interceptor to Ma…
joshk authored Apr 2, 2011
412 def register_observer(observer)
cb9e501 @joshk AM register_interceptor and register_observer only constantize if the…
joshk authored Apr 4, 2011
413 delivery_observer = (observer.is_a?(String) ? observer.constantize : observer)
284ca81 @joshk remove AM delegating register_observer and register_interceptor to Ma…
joshk authored Apr 2, 2011
414 Mail.register_observer(delivery_observer)
415 end
416
a467983 @vijaydev fix typo
vijaydev authored Jun 8, 2011
417 # Register an Interceptor which will be called before mail is sent.
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
418 # Either a class or a string can be passed in as the Interceptor. If a string is passed in
419 # it will be <tt>constantize</tt>d.
284ca81 @joshk remove AM delegating register_observer and register_interceptor to Ma…
joshk authored Apr 2, 2011
420 def register_interceptor(interceptor)
cb9e501 @joshk AM register_interceptor and register_observer only constantize if the…
joshk authored Apr 4, 2011
421 delivery_interceptor = (interceptor.is_a?(String) ? interceptor.constantize : interceptor)
284ca81 @joshk remove AM delegating register_observer and register_interceptor to Ma…
joshk authored Apr 2, 2011
422 Mail.register_interceptor(delivery_interceptor)
423 end
424
bd5ed65 @technoweenie Update ActionMailer so it treats ActionView the same way that ActionC…
technoweenie authored Nov 26, 2007
425 def mailer_name
c17d200 @lest mailer can be anonymous
lest authored May 13, 2012
426 @mailer_name ||= anonymous? ? "anonymous" : name.underscore
bd5ed65 @technoweenie Update ActionMailer so it treats ActionView the same way that ActionC…
technoweenie authored Nov 26, 2007
427 end
0750304 @mikel Migrated over to Mail doing delivery.
mikel authored Jan 16, 2010
428 attr_writer :mailer_name
429 alias :controller_path :mailer_name
81c416b @josevalim More refactoring on ActionMailer::Base.
josevalim authored Oct 28, 2009
430
e5ab4b0 @jeremy Convert to class_attribute
jeremy authored Feb 1, 2010
431 def default(value = nil)
432 self.default_params = default_params.merge(value).freeze if value
433 default_params
9dd65c3 Make defaults accept a hash.
José Valim and Mikel Lindsaar authored Jan 26, 2010
434 end
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
435 # Allows to set defaults through app configuration:
3009c63 @carlosantoniodasilva Improve docs, changelog and release notes for Action Mailer default_o…
carlosantoniodasilva authored Jul 7, 2012
436 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
437 # config.action_mailer.default_options = { from: "no-reply@example.org" }
edaa2c4 @paneq Introduce config.action_mailer.default_from=
paneq authored Jun 15, 2012
438 alias :default_options= :default
9dd65c3 Make defaults accept a hash.
José Valim and Mikel Lindsaar authored Jan 26, 2010
439
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored Oct 16, 2005
440 # Receives a raw email, parses it into an email object, decodes it,
441 # instantiates a new mailer, and passes the email object to the mailer
98dc582 @lifo Merge docrails.
lifo authored May 25, 2008
442 # object's +receive+ method. If you want your mailer to be able to
443 # process incoming messages, you'll need to implement a +receive+
bb2c7b4 @mikel Updating Action Mailer documentation
mikel authored Jan 29, 2010
444 # method that accepts the raw email string as a parameter:
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored Oct 16, 2005
445 #
446 # class MyMailer < ActionMailer::Base
447 # def receive(mail)
448 # ...
449 # end
450 # end
704daad @josevalim Ensure we just send Ruby Stdlib objects in ActionMailer notifications.
josevalim authored Jan 15, 2010
451 def receive(raw_mail)
731d439 @jaggederest Change event namespace ordering to most-significant first [#4504 stat…
jaggederest authored Apr 27, 2010
452 ActiveSupport::Notifications.instrument("receive.action_mailer") do |payload|
704daad @josevalim Ensure we just send Ruby Stdlib objects in ActionMailer notifications.
josevalim authored Jan 15, 2010
453 mail = Mail.new(raw_mail)
454 set_payload_for_mail(payload, mail)
2a6bc12 @josevalim Add subscriber to ActionMailer.
josevalim authored Jan 13, 2010
455 new.receive(mail)
456 end
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but …
jamis authored Jul 31, 2005
457 end
458
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
459 # Wraps an email delivery inside of Active Support Notifications instrumentation. This
460 # method is actually called by the <tt>Mail::Message</tt> object itself through a callback
461 # when you call <tt>:deliver</tt> on the Mail::Message, calling +deliver_mail+ directly
462 # and passing a Mail::Message will do nothing except tell the logger you sent the email.
463 def deliver_mail(mail) #:nodoc:
731d439 @jaggederest Change event namespace ordering to most-significant first [#4504 stat…
jaggederest authored Apr 28, 2010
464 ActiveSupport::Notifications.instrument("deliver.action_mailer") do |payload|
c176397 @sachin87 some modifications in action_mailer/base.rb
sachin87 authored Jan 22, 2012
465 set_payload_for_mail(payload, mail)
ace7497 Got AM working with Mail yield on delivery_handler and updated tests
José Valim and Mikel Lindsaar authored Jan 25, 2010
466 yield # Let Mail do the delivery actions
258ca14 Delegated ActionMailer::Base.deliveries to Mail.deliveries, added cal…
José Valim and Mikel Lindsaar authored Jan 24, 2010
467 end
468 end
469
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
470 def respond_to?(method, include_private = false) #:nodoc:
99f960a Handle some TODOs and deprecations.
José Valim and Mikel Lindsaar authored Jan 24, 2010
471 super || action_methods.include?(method.to_s)
472 end
473
474 protected
475
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
476 def set_payload_for_mail(payload, mail) #:nodoc:
e8c9cac @tenderlove self is implied, so remove self
tenderlove authored Sep 29, 2010
477 payload[:mailer] = name
c905fce @josevalim Add message_id to AM payload and don't send bcc and cc if they were n…
josevalim authored Jan 15, 2010
478 payload[:message_id] = mail.message_id
479 payload[:subject] = mail.subject
480 payload[:to] = mail.to
481 payload[:from] = mail.from
482 payload[:bcc] = mail.bcc if mail.bcc.present?
483 payload[:cc] = mail.cc if mail.cc.present?
484 payload[:date] = mail.date
485 payload[:mail] = mail.encoded
704daad @josevalim Ensure we just send Ruby Stdlib objects in ActionMailer notifications.
josevalim authored Jan 15, 2010
486 end
f30d73b Add new class delivery method API.
José Valim and Mikel Lindsaar authored Jan 24, 2010
487
34b23e7 @spastorino Action Mailer async flag is true by default using a Synchronous impl
spastorino authored Sep 10, 2012
488 def method_missing(method_name, *args)
489 if action_methods.include?(method_name.to_s)
490 QueuedMessage.new(queue, self, method_name, *args)
7e0cf56 @jonleighton Support `Mailer.deliver_foo(*args)` as a synonym for `Mailer.foo(*arg…
jonleighton authored Sep 28, 2012
491 elsif method_name.to_s =~ /^deliver_(.+)$/ && action_methods.include?($1)
492 public_send($1, *args).deliver
34b23e7 @spastorino Action Mailer async flag is true by default using a Synchronous impl
spastorino authored Sep 10, 2012
493 else
494 super
495 end
496 end
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but …
jamis authored Jul 31, 2005
497 end
498
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
499 attr_internal :message
500
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
501 # Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer
502 # will be initialized according to the named method. If not, the mailer will
503 # remain uninitialized (useful when you only need to invoke the "receive"
504 # method, for instance).
505 def initialize(method_name=nil, *args)
506 super()
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
507 @_message = Mail.new
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
508 process(method_name, *args) if method_name
509 end
510
3fc609e @josevalim Fix ActionMailer test broken in 99d5459
josevalim authored Apr 12, 2010
511 def process(*args) #:nodoc:
512 lookup_context.skip_default_locale!
513 super
514 end
515
972efa1 @josevalim Deprecate the old mailer API that was not deprecated yet.
josevalim authored Aug 29, 2010
516 def mailer_name
517 self.class.mailer_name
518 end
519
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
520 # Allows you to pass random and unusual headers to the new <tt>Mail::Message</tt> object
521 # which will add them to itself.
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
522 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
523 # headers['X-Special-Domain-Specific-Header'] = "SecretValue"
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
524 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
525 # You can also pass a hash into headers of header field names and values, which
526 # will then be set on the Mail::Message object:
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
527 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
528 # headers 'X-Special-Domain-Specific-Header' => "SecretValue",
05c4ad9 Tidy up tests and docs.
José Valim and Mikel Lindsaar authored Jan 26, 2010
529 # 'In-Reply-To' => incoming.message_id
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
530 #
ff44c33 @mark-rushakoff Fix it's -> its
mark-rushakoff authored Apr 27, 2012
531 # The resulting Mail::Message will have the following in its header:
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
532 #
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
533 # X-Special-Domain-Specific-Header: SecretValue
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
534 def headers(args=nil)
535 if args
9520166 @mikel Fixed up being able to pass random headers in with headers, or mail. …
mikel authored Jan 26, 2010
536 @_message.headers(args)
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
537 else
538 @_message
539 end
540 end
c34cfcc @mikel Created mail method for new API
mikel authored Jan 20, 2010
541
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
542 # Allows you to add attachments to an email, like so:
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
543 #
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
544 # mail.attachments['filename.jpg'] = File.read('/path/to/filename.jpg')
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
545 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
546 # If you do this, then Mail will take the file name and work out the mime type
547 # set the Content-Type, Content-Disposition, Content-Transfer-Encoding and
548 # base64 encode the contents of the attachment all for you.
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
549 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
550 # You can also specify overrides if you want by passing a hash instead of a string:
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
551 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
552 # mail.attachments['filename.jpg'] = {:mime_type => 'application/x-gzip',
553 # :content => File.read('/path/to/filename.jpg')}
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
554 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
555 # If you want to use a different encoding than Base64, you can pass an encoding in,
556 # but then it is up to you to pass in the content pre-encoded, and don't expect
557 # Mail to know how to decode this data:
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
558 #
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
559 # file_content = SpecialEncode(File.read('/path/to/filename.jpg'))
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
560 # mail.attachments['filename.jpg'] = {:mime_type => 'application/x-gzip',
561 # :encoding => 'SpecialEncoding',
562 # :content => file_content }
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
563 #
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
564 # You can also search for specific attachments:
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
565 #
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
566 # # By Filename
755af49 @fxn edit pass to apply API guideline wrt the use of "# =>" in example code
fxn authored Jul 30, 2010
567 # mail.attachments['filename.jpg'] # => Mail::Part object or nil
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
568 #
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
569 # # or by index
755af49 @fxn edit pass to apply API guideline wrt the use of "# =>" in example code
fxn authored Jul 30, 2010
570 # mail.attachments[0] # => Mail::Part (first attachment)
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
571 #
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
572 def attachments
573 @_message.attachments
574 end
dcb9253 Add basic template rendering to new DSL.
José Valim and Mikel Lindsaar authored Jan 22, 2010
575
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
576 # The main method that creates the message and renders the email templates. There are
577 # two ways to call this method, with a block, or without a block.
578 #
579 # Both methods accept a headers hash. This hash allows you to specify the most used headers
580 # in an email message, these are:
581 #
582 # * <tt>:subject</tt> - The subject of the message, if this is omitted, Action Mailer will
583 # ask the Rails I18n class for a translated <tt>:subject</tt> in the scope of
584 # <tt>[mailer_scope, action_name]</tt> or if this is missing, will translate the
585 # humanized version of the <tt>action_name</tt>
586 # * <tt>:to</tt> - Who the message is destined for, can be a string of addresses, or an array
587 # of addresses.
588 # * <tt>:from</tt> - Who the message is from
589 # * <tt>:cc</tt> - Who you would like to Carbon-Copy on this email, can be a string of addresses,
590 # or an array of addresses.
591 # * <tt>:bcc</tt> - Who you would like to Blind-Carbon-Copy on this email, can be a string of
592 # addresses, or an array of addresses.
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
593 # * <tt>:reply_to</tt> - Who to set the Reply-To header of the email to.
594 # * <tt>:date</tt> - The date to say the email was sent on.
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
595 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
596 # You can set default values for any of the above headers (except :date) by using the <tt>default</tt>
597 # class method:
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
598 #
9dd65c3 Make defaults accept a hash.
José Valim and Mikel Lindsaar authored Jan 26, 2010
599 # class Notifier < ActionMailer::Base
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
600 # self.default :from => 'no-reply@test.lindsaar.net',
601 # :bcc => 'email_logger@test.lindsaar.net',
602 # :reply_to => 'bounces@test.lindsaar.net'
0b05acd @mikel Implementing class level :defaults hash, instead of delivers_from et al
mikel authored Jan 26, 2010
603 # end
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
604 #
52c56f9 @wincent docs: note that mail() accepts arbitrary headers
wincent authored Jun 29, 2010
605 # If you need other headers not listed above, you can either pass them in
606 # as part of the headers hash or use the <tt>headers['name'] = value</tt>
607 # method.
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
608 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
609 # When a <tt>:return_path</tt> is specified as header, that value will be used as the 'envelope from'
610 # address for the Mail message. Setting this is useful when you want delivery notifications
611 # sent to a different address than the one in <tt>:from</tt>. Mail will actually use the
612 # <tt>:return_path</tt> in preference to the <tt>:sender</tt> in preference to the <tt>:from</tt>
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
613 # field for the 'envelope from' value.
614 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
615 # If you do not pass a block to the +mail+ method, it will find all templates in the
616 # view paths using by default the mailer name and the method name that it is being
617 # called from, it will then create parts for each of these templates intelligently,
618 # making educated guesses on correct content type and sequence, and return a fully
619 # prepared Mail::Message ready to call <tt>:deliver</tt> on to send.
be35a15 @josevalim Allow to choose the template path and template name used in implicit …
josevalim authored Feb 19, 2010
620 #
621 # For example:
622 #
623 # class Notifier < ActionMailer::Base
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
624 # default :from => 'no-reply@test.lindsaar.net',
be35a15 @josevalim Allow to choose the template path and template name used in implicit …
josevalim authored Feb 19, 2010
625 #
626 # def welcome
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
627 # mail(:to => 'mikel@test.lindsaar.net')
be35a15 @josevalim Allow to choose the template path and template name used in implicit …
josevalim authored Feb 19, 2010
628 # end
629 # end
630 #
45b1045 @dmathieu raise an error if no implicit mailer template could be found
dmathieu authored Jun 20, 2012
631 # Will look for all templates at "app/views/notifier" with name "welcome".
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
632 # If no welcome template exists, it will raise an ActionView::MissingTemplate error.
45b1045 @dmathieu raise an error if no implicit mailer template could be found
dmathieu authored Jun 20, 2012
633 #
634 # However, those can be customized:
be35a15 @josevalim Allow to choose the template path and template name used in implicit …
josevalim authored Feb 19, 2010
635 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
636 # mail(:template_path => 'notifications', :template_name => 'another')
be35a15 @josevalim Allow to choose the template path and template name used in implicit …
josevalim authored Feb 19, 2010
637 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
638 # And now it will look for all templates at "app/views/notifications" with name "another".
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
639 #
640 # If you do pass a block, you can render specific templates of your choice:
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
641 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
642 # mail(:to => 'mikel@test.lindsaar.net') do |format|
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
643 # format.text
644 # format.html
645 # end
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
646 #
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
647 # You can even render text directly without using a template:
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
648 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
649 # mail(:to => 'mikel@test.lindsaar.net') do |format|
650 # format.text { render :text => "Hello Mikel!" }
651 # format.html { render :text => "<h1>Hello Mikel!</h1>" }
4a6eba3 Added initial documentation for the new API
José Valim and Mikel Lindsaar authored Jan 25, 2010
652 # end
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
653 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
654 # Which will render a <tt>multipart/alternative</tt> email with <tt>text/plain</tt> and
655 # <tt>text/html</tt> parts.
6589976 Remove old files, add some information to docs and improve test suite.
José Valim and Mikel Lindsaar authored Jan 26, 2010
656 #
657 # The block syntax also allows you to customize the part headers if desired:
658 #
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
659 # mail(:to => 'mikel@test.lindsaar.net') do |format|
660 # format.text(:content_transfer_encoding => "base64")
6589976 Remove old files, add some information to docs and improve test suite.
José Valim and Mikel Lindsaar authored Jan 26, 2010
661 # format.html
662 # end
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
663 #
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
664 def mail(headers={}, &block)
665 m = @_message
258ca14 Delegated ActionMailer::Base.deliveries to Mail.deliveries, added cal…
José Valim and Mikel Lindsaar authored Jan 24, 2010
666
9dd65c3 Make defaults accept a hash.
José Valim and Mikel Lindsaar authored Jan 26, 2010
667 # At the beginning, do not consider class default for parts order neither content_type
668 content_type = headers[:content_type]
669 parts_order = headers[:parts_order]
1cd5592 First work on implicit multipart.
José Valim and Mikel Lindsaar authored Jan 22, 2010
670
08b07b6 @mikel Adding ability to pass proc's to the ActionMailer class default method
mikel authored May 2, 2010
671 # Call all the procs (if any)
c176397 @sachin87 some modifications in action_mailer/base.rb
sachin87 authored Jan 21, 2012
672 class_default = self.class.default
673 default_values = class_default.merge(class_default) do |k,v|
3fbc042 @lest Use instance_eval instead of Proc#bind
lest authored Jan 23, 2012
674 v.respond_to?(:to_proc) ? instance_eval(&v) : v
08b07b6 @mikel Adding ability to pass proc's to the ActionMailer class default method
mikel authored May 2, 2010
675 end
458f571 @wycats Remove the need for a special action_mailer.url_for initializer that …
wycats authored May 15, 2010
676
b5f9a9f @josevalim Move set_fields! to the old API module.
josevalim authored Apr 12, 2010
677 # Handle defaults
08b07b6 @mikel Adding ability to pass proc's to the ActionMailer class default method
mikel authored May 2, 2010
678 headers = headers.reverse_merge(default_values)
9dd65c3 Make defaults accept a hash.
José Valim and Mikel Lindsaar authored Jan 26, 2010
679 headers[:subject] ||= default_i18n_subject
b5f9a9f @josevalim Move set_fields! to the old API module.
josevalim authored Apr 12, 2010
680
681 # Apply charset at the beginning so all fields are properly quoted
682 m.charset = charset = headers[:charset]
683
684 # Set configure delivery behavior
8fc8763 @asanghi Allow delivery method options to be set per mail instance
asanghi authored Aug 20, 2012
685 wrap_delivery_behavior!(headers.delete(:delivery_method),headers.delete(:delivery_method_options))
b5f9a9f @josevalim Move set_fields! to the old API module.
josevalim authored Apr 12, 2010
686
687 # Assign all headers except parts_order, content_type and body
b4fd5e6 @josevalim template_name and template_path should not be added to mail headers.
josevalim authored Apr 13, 2010
688 assignable = headers.except(:parts_order, :content_type, :body, :template_name, :template_path)
b5f9a9f @josevalim Move set_fields! to the old API module.
josevalim authored Apr 12, 2010
689 assignable.each { |k, v| m[k] = v }
951397b Get implicit multipart and attachments working together.
José Valim and Mikel Lindsaar authored Jan 22, 2010
690
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
691 # Render the templates and blocks
39a1b06 Deprecate old defaults API.
José Valim and Mikel Lindsaar authored Jan 26, 2010
692 responses, explicit_order = collect_responses_and_parts_order(headers, &block)
b5f9a9f @josevalim Move set_fields! to the old API module.
josevalim authored Apr 12, 2010
693 create_parts_from_responses(m, responses)
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
694
b5f9a9f @josevalim Move set_fields! to the old API module.
josevalim authored Apr 12, 2010
695 # Setup content type, reapply charset and handle parts order
9dd65c3 Make defaults accept a hash.
José Valim and Mikel Lindsaar authored Jan 26, 2010
696 m.content_type = set_content_type(m, content_type, headers[:content_type])
951397b Get implicit multipart and attachments working together.
José Valim and Mikel Lindsaar authored Jan 22, 2010
697 m.charset = charset
698
e7e4ed4 Set sort order for explicit parts from the collector's template sequence
José Valim and Mikel Lindsaar authored Jan 24, 2010
699 if m.multipart?
9dd65c3 Make defaults accept a hash.
José Valim and Mikel Lindsaar authored Jan 26, 2010
700 parts_order ||= explicit_order || headers[:parts_order]
701 m.body.set_sort_order(parts_order)
951397b Get implicit multipart and attachments working together.
José Valim and Mikel Lindsaar authored Jan 22, 2010
702 m.body.sort_parts!
703 end
bb9d71f Move class methods to deprecated stuff.
José Valim and Mikel Lindsaar authored Jan 22, 2010
704
c34cfcc @mikel Created mail method for new API
mikel authored Jan 20, 2010
705 m
706 end
707
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
708 protected
709
9dd65c3 Make defaults accept a hash.
José Valim and Mikel Lindsaar authored Jan 26, 2010
710 def set_content_type(m, user_content_type, class_default)
74a5889 Refactor content type setting, added tests to ensure boundary exists …
José Valim and Mikel Lindsaar authored Jan 26, 2010
711 params = m.content_type_parameters || {}
712 case
713 when user_content_type.present?
714 user_content_type
715 when m.has_attachments?
311d99e @mikel Adding inline attachment support to ActionMailer
mikel authored Jun 7, 2010
716 if m.attachments.detect { |a| a.inline? }
717 ["multipart", "related", params]
718 else
719 ["multipart", "mixed", params]
720 end
74a5889 Refactor content type setting, added tests to ensure boundary exists …
José Valim and Mikel Lindsaar authored Jan 26, 2010
721 when m.multipart?
722 ["multipart", "alternative", params]
723 else
b6b3db6 @mikel Fixed bug on HTML only emails getting set to text/plain
mikel authored Jan 28, 2010
724 m.content_type || class_default
74a5889 Refactor content type setting, added tests to ensure boundary exists …
José Valim and Mikel Lindsaar authored Jan 26, 2010
725 end
726 end
727
0e288ec @rafaelfranca Revert "update ActionMailer::Base documentation [ci skip]"
rafaelfranca authored Sep 21, 2012
728 # Translates the +subject+ using Rails I18n class under <tt>[mailer_scope, action_name]</tt> scope.
729 # If it does not find a translation for the +subject+ under the specified scope it will default to a
730 # humanized version of the <tt>action_name</tt>.
731 def default_i18n_subject #:nodoc:
2d8396f @jurriaan Updated/changed useless tr/gsubs
jurriaan authored Apr 3, 2012
732 mailer_scope = self.class.mailer_name.tr('/', '.')
30eaecb @josevalim subject is automatically looked up on I18n using mailer_name and acti…
josevalim authored Jun 12, 2010
733 I18n.t(:subject, :scope => [mailer_scope, action_name], :default => action_name.humanize)
5c3ef8c Refactor subject with i18n.
José Valim and Mikel Lindsaar authored Jan 23, 2010
734 end
735
39a1b06 Deprecate old defaults API.
José Valim and Mikel Lindsaar authored Jan 26, 2010
736 def collect_responses_and_parts_order(headers) #:nodoc:
737 responses, parts_order = [], nil
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
738
739 if block_given?
a09e992 @josevalim Ensure details are frozen after @details_keys lookup. The implementat…
josevalim authored Mar 27, 2010
740 collector = ActionMailer::Collector.new(lookup_context) { render(action_name) }
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
741 yield(collector)
39a1b06 Deprecate old defaults API.
José Valim and Mikel Lindsaar authored Jan 26, 2010
742 parts_order = collector.responses.map { |r| r[:content_type] }
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
743 responses = collector.responses
744 elsif headers[:body]
745 responses << {
be35a15 @josevalim Allow to choose the template path and template name used in implicit …
josevalim authored Feb 19, 2010
746 :body => headers.delete(:body),
452bb1e @jeremy Rename 'defaults' class method to 'default' to reflect that it's a de…
jeremy authored Jan 27, 2010
747 :content_type => self.class.default[:content_type] || "text/plain"
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
748 }
749 else
be35a15 @josevalim Allow to choose the template path and template name used in implicit …
josevalim authored Feb 19, 2010
750 templates_path = headers.delete(:template_path) || self.class.mailer_name
751 templates_name = headers.delete(:template_name) || action_name
752
753 each_template(templates_path, templates_name) do |template|
f28d856 @josevalim Improve performance of the rendering stack by freezing formats as a s…
josevalim authored Mar 19, 2010
754 self.formats = template.formats
755
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
756 responses << {
2a12686 @josevalim Allow anything that responds to render to be given as :template and u…
josevalim authored Mar 12, 2010
757 :body => render(:template => template),
167f250 @kennyj Fixes warnings when executing rake test in ActionMailer. Related to 5…
kennyj authored Aug 29, 2012
758 :content_type => template.type.to_s
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
759 }
760 end
761 end
762
39a1b06 Deprecate old defaults API.
José Valim and Mikel Lindsaar authored Jan 26, 2010
763 [responses, parts_order]
7409b73 Some refactoring.
José Valim and Mikel Lindsaar authored Jan 24, 2010
764 end
765
be35a15 @josevalim Allow to choose the template path and template name used in implicit …
josevalim authored Feb 19, 2010
766 def each_template(paths, name, &block) #:nodoc:
3438f6c @rafaelfranca Array.wrap is no longer needed here
rafaelfranca authored Jan 5, 2012
767 templates = lookup_context.find_all(name, Array(paths))
45b1045 @dmathieu raise an error if no implicit mailer template could be found
dmathieu authored Jun 20, 2012
768 if templates.empty?
769 raise ActionView::MissingTemplate.new([paths], name, [paths], false, 'mailer')
770 else
771 templates.uniq { |t| t.formats }.each(&block)
772 end
99f960a Handle some TODOs and deprecations.
José Valim and Mikel Lindsaar authored Jan 24, 2010
773 end
774
b5f9a9f @josevalim Move set_fields! to the old API module.
josevalim authored Apr 12, 2010
775 def create_parts_from_responses(m, responses) #:nodoc:
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
776 if responses.size == 1 && !m.has_attachments?
9dd65c3 Make defaults accept a hash.
José Valim and Mikel Lindsaar authored Jan 26, 2010
777 responses[0].each { |k,v| m[k] = v }
74a5889 Refactor content type setting, added tests to ensure boundary exists …
José Valim and Mikel Lindsaar authored Jan 26, 2010
778 elsif responses.size > 1 && m.has_attachments?
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
779 container = Mail::Part.new
74a5889 Refactor content type setting, added tests to ensure boundary exists …
José Valim and Mikel Lindsaar authored Jan 26, 2010
780 container.content_type = "multipart/alternative"
b5f9a9f @josevalim Move set_fields! to the old API module.
josevalim authored Apr 12, 2010
781 responses.each { |r| insert_part(container, r, m.charset) }
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
782 m.add_part(container)
783 else
b5f9a9f @josevalim Move set_fields! to the old API module.
josevalim authored Apr 12, 2010
784 responses.each { |r| insert_part(m, r, m.charset) }
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
785 end
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored May 29, 2005
786 end
787
6ba9446 Make implicit and explicit templates pass through the same part creat…
José Valim and Mikel Lindsaar authored Jan 23, 2010
788 def insert_part(container, response, charset) #:nodoc:
789 response[:charset] ||= charset
790 part = Mail::Part.new(response)
791 container.add_part(part)
359caef @jamis A very thorough refactoring, resulting in new mail property setters a…
jamis authored May 29, 2005
792 end
3fad0cd @dhh Added support for charsets for both subject and body. The default cha…
dhh authored Feb 19, 2005
793
ef5dada @nex3 Only run load hooks once a file has been fully loaded.
nex3 authored Apr 27, 2010
794 ActiveSupport.run_load_hooks(:action_mailer, self)
db045db @dhh Initial
dhh authored Nov 24, 2004
795 end
edaa2c4 @paneq Introduce config.action_mailer.default_from=
paneq authored Jun 15, 2012
796 end
Something went wrong with that request. Please try again.