Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 657 lines (573 sloc) 26.856 kb
a9751a7 José Valim Refactor ActionMailer layout and remove legacy one.
josevalim authored
1 require 'active_support/core_ext/class'
a63caa4 Get tests to run (with failures) without old base around
Yehuda Katz + Carl Lerche authored
2
c4590d5 David Heinemeier Hansson Fixed docs
dhh authored
3 module ActionMailer #:nodoc:
98dc582 Pratik Merge docrails.
lifo authored
4 # Action Mailer allows you to send email from your application using a mailer model and views.
db045db David Heinemeier Hansson Initial
dhh authored
5 #
20bd4bd David Heinemeier Hansson Updated docs and otherwise
dhh authored
6 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
7 # = Mailer Models
20bd4bd David Heinemeier Hansson Updated docs and otherwise
dhh authored
8 #
98dc582 Pratik Merge docrails.
lifo authored
9 # To use Action Mailer, you need to create a mailer model.
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
10 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
11 # $ script/generate mailer Notifier
12 #
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
13 # The generated model inherits from ActionMailer::Base. Emails are defined by creating methods within the model which are then
14 # used to set variables to be used in the mail template, to change options on the mail, or
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
15 # to add attachments.
16 #
17 # Examples:
18 #
19 # class Notifier < ActionMailer::Base
20 # def signup_notification(recipient)
21 # recipients recipient.email_address_with_name
c3f53f4 Pratik Merge docrails
lifo authored
22 # bcc ["bcc@example.com", "Order Watcher <watcher@example.com>"]
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
23 # from "system@example.com"
24 # subject "New account information"
20bd4bd David Heinemeier Hansson Updated docs and otherwise
dhh authored
25 # body :account => recipient
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
26 # end
27 # end
28 #
29 # Mailer methods have the following configuration methods available.
30 #
31 # * <tt>recipients</tt> - Takes one or more email addresses. These addresses are where your email will be delivered to. Sets the <tt>To:</tt> header.
32 # * <tt>subject</tt> - The subject of your email. Sets the <tt>Subject:</tt> header.
33 # * <tt>from</tt> - Who the email you are sending is from. Sets the <tt>From:</tt> header.
34 # * <tt>cc</tt> - Takes one or more email addresses. These addresses will receive a carbon copy of your email. Sets the <tt>Cc:</tt> header.
cf6299d Add ActionMailer#reply_to. [#245 state:resolved]
Adam authored
35 # * <tt>bcc</tt> - Takes one or more email addresses. These addresses will receive a blind carbon copy of your email. Sets the <tt>Bcc:</tt> header.
36 # * <tt>reply_to</tt> - Takes one or more email addresses. These addresses will be listed as the default recipients when replying to your email. Sets the <tt>Reply-To:</tt> header.
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
37 # * <tt>sent_on</tt> - The date on which the message was sent. If not set, the header wil be set by the delivery agent.
38 # * <tt>content_type</tt> - Specify the content type of the message. Defaults to <tt>text/plain</tt>.
39 # * <tt>headers</tt> - Specify additional headers to be set for the message, e.g. <tt>headers 'X-Mail-Count' => 107370</tt>.
40 #
5c0d38f David Heinemeier Hansson Fixed that a return-path header would be ignored (closes #7572) [joost]
dhh authored
41 # When a <tt>headers 'return-path'</tt> is specified, that value will be used as the 'envelope from'
42 # address. Setting this is useful when you want delivery notifications sent to a different address than
43 # the one in <tt>from</tt>.
44 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
45 # The <tt>body</tt> method has special behavior. It takes a hash which generates an instance variable
46 # named after each key in the hash containing the value that that key points to.
47 #
5c0d38f David Heinemeier Hansson Fixed that a return-path header would be ignored (closes #7572) [joost]
dhh authored
48 # So, for example, <tt>body :account => recipient</tt> would result
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
49 # in an instance variable <tt>@account</tt> with the value of <tt>recipient</tt> being accessible in the
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
50 # view.
51 #
20bd4bd David Heinemeier Hansson Updated docs and otherwise
dhh authored
52 #
53 # = Mailer views
54 #
98dc582 Pratik Merge docrails.
lifo authored
55 # Like Action Controller, each mailer class has a corresponding view directory
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
56 # in which each method of the class looks for a template with its name.
21187c0 David Heinemeier Hansson Apply the rest of Chads patch
dhh authored
57 # To define a template to be used with a mailing, create an <tt>.erb</tt> file with the same name as the method
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
58 # in your mailer model. For example, in the mailer defined above, the template at
21187c0 David Heinemeier Hansson Apply the rest of Chads patch
dhh authored
59 # <tt>app/views/notifier/signup_notification.erb</tt> would be used to generate the email.
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
60 #
61 # Variables defined in the model are accessible as instance variables in the view.
62 #
63 # Emails by default are sent in plain text, so a sample view for our model example might look like this:
64 #
65 # Hi <%= @account.name %>,
66 # Thanks for joining our service! Please check back often.
67 #
20bd4bd David Heinemeier Hansson Updated docs and otherwise
dhh authored
68 # You can even use Action Pack helpers in these views. For example:
69 #
70 # You got a new note!
71 # <%= truncate(note.body, 25) %>
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
72 #
20bd4bd David Heinemeier Hansson Updated docs and otherwise
dhh authored
73 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
74 # = Generating URLs
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
75 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
76 # URLs can be generated in mailer views using <tt>url_for</tt> or named routes.
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
77 # Unlike controllers from Action Pack, the mailer instance doesn't have any context about the incoming request,
78 # so you'll need to provide all of the details needed to generate a URL.
20bd4bd David Heinemeier Hansson Updated docs and otherwise
dhh authored
79 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
80 # When using <tt>url_for</tt> you'll need to provide the <tt>:host</tt>, <tt>:controller</tt>, and <tt>:action</tt>:
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
81 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
82 # <%= url_for(:host => "example.com", :controller => "welcome", :action => "greeting") %>
20bd4bd David Heinemeier Hansson Updated docs and otherwise
dhh authored
83 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
84 # When using named routes you only need to supply the <tt>:host</tt>:
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
85 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
86 # <%= users_url(:host => "example.com") %>
87 #
88 # You will want to avoid using the <tt>name_of_route_path</tt> form of named routes because it doesn't make sense to
89 # generate relative URLs in email messages.
90 #
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
91 # It is also possible to set a default host that will be used in all mailers by setting the <tt>:host</tt> option in
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
92 # the <tt>ActionMailer::Base.default_url_options</tt> hash as follows:
93 #
94 # ActionMailer::Base.default_url_options[:host] = "example.com"
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
95 #
dc4eec1 Pratik Merge docrails:
lifo authored
96 # This can also be set as a configuration option in <tt>config/environment.rb</tt>:
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
97 #
98 # config.action_mailer.default_url_options = { :host => "example.com" }
20bd4bd David Heinemeier Hansson Updated docs and otherwise
dhh authored
99 #
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
100 # If you do decide to set a default <tt>:host</tt> for your mailers you will want to use the
101 # <tt>:only_path => false</tt> option when using <tt>url_for</tt>. This will ensure that absolute URLs are generated because
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
102 # the <tt>url_for</tt> view helper will, by default, generate relative URLs when a <tt>:host</tt> option isn't
4809dcc * Remove default_url_options from mailer generator
Cody Fauser authored
103 # explicitly provided.
20bd4bd David Heinemeier Hansson Updated docs and otherwise
dhh authored
104 #
105 # = Sending mail
106 #
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
107 # Once a mailer action and template are defined, you can deliver your message or create it and save it
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
108 # for delivery later:
109 #
110 # Notifier.deliver_signup_notification(david) # sends the email
111 # mail = Notifier.create_signup_notification(david) # => a tmail object
112 # Notifier.deliver(mail)
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
113 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
114 # You never instantiate your mailer class. Rather, your delivery instance
115 # methods are automatically wrapped in class methods that start with the word
116 # <tt>deliver_</tt> followed by the name of the mailer method that you would
117 # like to deliver. The <tt>signup_notification</tt> method defined above is
118 # delivered by invoking <tt>Notifier.deliver_signup_notification</tt>.
119 #
20bd4bd David Heinemeier Hansson Updated docs and otherwise
dhh authored
120 #
121 # = HTML email
122 #
21187c0 David Heinemeier Hansson Apply the rest of Chads patch
dhh authored
123 # To send mail as HTML, make sure your view (the <tt>.erb</tt> file) generates HTML and
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
124 # set the content type to html.
125 #
126 # class MyMailer < ActionMailer::Base
359caef Jamis Buck A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
127 # def signup_notification(recipient)
46f30f9 Pratik Merge documentation changes from docrails.
lifo authored
128 # recipients recipient.email_address_with_name
129 # subject "New account information"
130 # from "system@example.com"
131 # body :account => recipient
132 # content_type "text/html"
359caef Jamis Buck A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
133 # end
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
134 # end
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
135 #
20bd4bd David Heinemeier Hansson Updated docs and otherwise
dhh authored
136 #
137 # = Multipart email
138 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
139 # You can explicitly specify multipart messages:
359caef Jamis Buck A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
140 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
141 # class ApplicationMailer < ActionMailer::Base
359caef Jamis Buck A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
142 # def signup_notification(recipient)
143 # recipients recipient.email_address_with_name
144 # subject "New account information"
145 # from "system@example.com"
46f30f9 Pratik Merge documentation changes from docrails.
lifo authored
146 # content_type "multipart/alternative"
359caef Jamis Buck A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
147 #
148 # part :content_type => "text/html",
149 # :body => render_message("signup-as-html", :account => recipient)
150 #
151 # part "text/plain" do |p|
152 # p.body = render_message("signup-as-plain", :account => recipient)
153 # p.transfer_encoding = "base64"
154 # end
155 # end
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
156 # end
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
157 #
98dc582 Pratik Merge docrails.
lifo authored
158 # Multipart messages can also be used implicitly because Action Mailer will automatically
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
159 # detect and use multipart templates, where each template is named after the name of the action, followed
160 # by the content type. Each such detected template will be added as separate part to the message.
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
161 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
162 # For example, if the following templates existed:
21187c0 David Heinemeier Hansson Apply the rest of Chads patch
dhh authored
163 # * signup_notification.text.plain.erb
164 # * signup_notification.text.html.erb
165 # * signup_notification.text.xml.builder
166 # * signup_notification.text.x-yaml.erb
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
167 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
168 # Each would be rendered and added as a separate part to the message,
46f30f9 Pratik Merge documentation changes from docrails.
lifo authored
169 # with the corresponding content type. The content type for the entire
170 # message is automatically set to <tt>multipart/alternative</tt>, which indicates
171 # that the email contains multiple different representations of the same email
172 # body. The same body hash is passed to each template.
359caef Jamis Buck A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
173 #
46f30f9 Pratik Merge documentation changes from docrails.
lifo authored
174 # Implicit template rendering is not performed if any attachments or parts have been added to the email.
175 # This means that you'll have to manually add each part to the email and set the content type of the email
176 # to <tt>multipart/alternative</tt>.
20bd4bd David Heinemeier Hansson Updated docs and otherwise
dhh authored
177 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
178 # = Attachments
20bd4bd David Heinemeier Hansson Updated docs and otherwise
dhh authored
179 #
0a407bc ActionMailer::Base documentation rewrite. Closes #4991 [Kevin Clark, Mar...
Marcel Molina authored
180 # Attachments can be added by using the +attachment+ method.
181 #
182 # Example:
183 #
184 # class ApplicationMailer < ActionMailer::Base
359caef Jamis Buck A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
185 # # attachments
186 # def signup_notification(recipient)
187 # recipients recipient.email_address_with_name
188 # subject "New account information"
189 # from "system@example.com"
190 #
191 # attachment :content_type => "image/jpeg",
192 # :body => File.read("an-image.jpg")
193 #
194 # attachment "application/pdf" do |a|
195 # a.body = generate_your_pdf_here()
196 # end
db045db David Heinemeier Hansson Initial
dhh authored
197 # end
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
198 # end
c927aa0 David Heinemeier Hansson Updated documentation
dhh authored
199 #
20bd4bd David Heinemeier Hansson Updated docs and otherwise
dhh authored
200 #
c927aa0 David Heinemeier Hansson Updated documentation
dhh authored
201 # = Configuration options
202 #
203 # These options are specified on the class level, like <tt>ActionMailer::Base.template_root = "/my/templates"</tt>
204 #
64092de Xavier Noria Improve documentation coverage and markup
fxn authored
205 # * <tt>template_root</tt> - Determines the base from which template references will be made.
c927aa0 David Heinemeier Hansson Updated documentation
dhh authored
206 #
207 # * <tt>logger</tt> - the logger is used for generating information on the mailing run if available.
208 # Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers.
209 #
64092de Xavier Noria Improve documentation coverage and markup
fxn authored
210 # * <tt>smtp_settings</tt> - Allows detailed configuration for <tt>:smtp</tt> delivery method:
dc4eec1 Pratik Merge docrails:
lifo authored
211 # * <tt>:address</tt> - Allows you to use a remote mail server. Just change it from its default "localhost" setting.
212 # * <tt>:port</tt> - On the off chance that your mail server doesn't run on port 25, you can change it.
213 # * <tt>:domain</tt> - If you need to specify a HELO domain, you can do it here.
214 # * <tt>:user_name</tt> - If your mail server requires authentication, set the username in this setting.
215 # * <tt>:password</tt> - If your mail server requires authentication, set the password in this setting.
b2504f8 Joshua Peek Tidy up ActionMailer rendering logic to take advantage of view path cach...
josh authored
216 # * <tt>:authentication</tt> - If your mail server requires authentication, you need to specify the authentication type here.
46f30f9 Pratik Merge documentation changes from docrails.
lifo authored
217 # This is a symbol and one of <tt>:plain</tt>, <tt>:login</tt>, <tt>:cram_md5</tt>.
c2e7851 José Valim Add ActionMailer::Base#enable_starttls_auto option for enabling/disablin...
josevalim authored
218 # * <tt>:enable_starttls_auto</tt> - When set to true, detects if STARTTLS is enabled in your SMTP server and starts to use it.
219 # It works only on Ruby >= 1.8.7 and Ruby >= 1.9. Default is true.
c927aa0 David Heinemeier Hansson Updated documentation
dhh authored
220 #
46f30f9 Pratik Merge documentation changes from docrails.
lifo authored
221 # * <tt>sendmail_settings</tt> - Allows you to override options for the <tt>:sendmail</tt> delivery method.
222 # * <tt>:location</tt> - The location of the sendmail executable. Defaults to <tt>/usr/sbin/sendmail</tt>.
223 # * <tt>:arguments</tt> - The command line arguments. Defaults to <tt>-i -t</tt>.
dc4eec1 Pratik Merge docrails:
lifo authored
224 #
fbe6c3c Eric Davis Adds a :file delivery_method to save email to a file on disk
edavis10 authored
225 # * <tt>file_settings</tt> - Allows you to override options for the <tt>:file</tt> delivery method.
226 # * <tt>:location</tt> - The directory into which emails will be written. Defaults to the application <tt>tmp/mails</tt>.
227 #
dc4eec1 Pratik Merge docrails:
lifo authored
228 # * <tt>raise_delivery_errors</tt> - Whether or not errors should be raised if the email fails to be delivered.
c927aa0 David Heinemeier Hansson Updated documentation
dhh authored
229 #
fbe6c3c Eric Davis Adds a :file delivery_method to save email to a file on disk
edavis10 authored
230 # * <tt>delivery_method</tt> - Defines a delivery method. Possible values are <tt>:smtp</tt> (default), <tt>:sendmail</tt>, <tt>:test</tt>,
f4f7677 Matthew Rudy Jacobs abstract all of the ActionMailer delivery methods into their own classes...
matthewrudy authored
231 # and <tt>:file</tt>. Or you may provide a custom delivery method object eg. MyOwnDeliveryMethodClass.new
c927aa0 David Heinemeier Hansson Updated documentation
dhh authored
232 #
dc4eec1 Pratik Merge docrails:
lifo authored
233 # * <tt>perform_deliveries</tt> - Determines whether <tt>deliver_*</tt> methods are actually carried out. By default they are,
c927aa0 David Heinemeier Hansson Updated documentation
dhh authored
234 # but this can be turned off to help functional testing.
235 #
64092de Xavier Noria Improve documentation coverage and markup
fxn authored
236 # * <tt>deliveries</tt> - Keeps an array of all the emails sent out through the Action Mailer with <tt>delivery_method :test</tt>. Most useful
c927aa0 David Heinemeier Hansson Updated documentation
dhh authored
237 # for unit and functional testing.
af56c80 David Heinemeier Hansson Updated documentation
dhh authored
238 #
b2504f8 Joshua Peek Tidy up ActionMailer rendering logic to take advantage of view path cach...
josh authored
239 # * <tt>default_charset</tt> - The default charset used for the body and to encode the subject. Defaults to UTF-8. You can also
46f30f9 Pratik Merge documentation changes from docrails.
lifo authored
240 # pick a different charset from inside a method with +charset+.
c2e7851 José Valim Add ActionMailer::Base#enable_starttls_auto option for enabling/disablin...
josevalim authored
241 #
475bd74 David Heinemeier Hansson Fix docs (closes #2598)
dhh authored
242 # * <tt>default_content_type</tt> - The default content type used for the main part of the message. Defaults to "text/plain". You
b2504f8 Joshua Peek Tidy up ActionMailer rendering logic to take advantage of view path cach...
josh authored
243 # can also pick a different content type from inside a method with +content_type+.
c2e7851 José Valim Add ActionMailer::Base#enable_starttls_auto option for enabling/disablin...
josevalim authored
244 #
46f30f9 Pratik Merge documentation changes from docrails.
lifo authored
245 # * <tt>default_mime_version</tt> - The default mime version used for the message. Defaults to <tt>1.0</tt>. You
246 # can also pick a different value from inside a method with +mime_version+.
c2e7851 José Valim Add ActionMailer::Base#enable_starttls_auto option for enabling/disablin...
josevalim authored
247 #
475bd74 David Heinemeier Hansson Fix docs (closes #2598)
dhh authored
248 # * <tt>default_implicit_parts_order</tt> - When a message is built implicitly (i.e. multiple parts are assembled from templates
5c98152 Jamis Buck Better multipart support with implicit multipart/alternative and sorting...
jamis authored
249 # which specify the content type in their filenames) this variable controls how the parts are ordered. Defaults to
46f30f9 Pratik Merge documentation changes from docrails.
lifo authored
250 # <tt>["text/html", "text/enriched", "text/plain"]</tt>. Items that appear first in the array have higher priority in the mail client
5c98152 Jamis Buck Better multipart support with implicit multipart/alternative and sorting...
jamis authored
251 # and appear last in the mime encoded message. You can also pick a different order from inside a method with
46f30f9 Pratik Merge documentation changes from docrails.
lifo authored
252 # +implicit_parts_order+.
db045db David Heinemeier Hansson Initial
dhh authored
253 class Base
15d7cac Mikel Lindsaar Starting again on actionmailer integration with mail
mikel authored
254 include AdvAttrAccessor, Quoting, Utils
a9751a7 José Valim Refactor ActionMailer layout and remove legacy one.
josevalim authored
255
256 include AbstractController::RenderingController
976c264 José Valim Extracted localized_cache.rb from ActionController, added it to Abstract...
josevalim authored
257 include AbstractController::LocalizedCache
a9751a7 José Valim Refactor ActionMailer layout and remove legacy one.
josevalim authored
258 include AbstractController::Layouts
09f798b José Valim Instrument create and deliver in ActionMailer.
josevalim authored
259
684c2dc José Valim Remove ActionMailer helpers and rely on AbstractController one.
josevalim authored
260 include AbstractController::Helpers
261 helper MailHelper
262
6228220 David Heinemeier Hansson Revert "Revert "Add layout functionality to mailers.""
dhh authored
263 if Object.const_defined?(:ActionController)
264 include ActionController::UrlWriter
265 end
359caef Jamis Buck A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
266
418c3f8 José Valim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
267 include ActionMailer::DeprecatedBody
268
c927aa0 David Heinemeier Hansson Updated documentation
dhh authored
269 private_class_method :new #:nodoc:
db045db David Heinemeier Hansson Initial
dhh authored
270
cb21db1 Joshua Peek Treat ActionMailer template_root as a view path set internally to avoid ...
josh authored
271 class_inheritable_accessor :view_paths
441e4e2 Sven Fuchs load plugin view_paths to action_mailer view_paths and make action_maile...
svenfuchs authored
272 self.view_paths = []
273
db045db David Heinemeier Hansson Initial
dhh authored
274 cattr_accessor :logger
275
276 @@raise_delivery_errors = true
277 cattr_accessor :raise_delivery_errors
278
279 @@perform_deliveries = true
280 cattr_accessor :perform_deliveries
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
281
db045db David Heinemeier Hansson Initial
dhh authored
282 @@deliveries = []
283 cattr_accessor :deliveries
284
3fad0cd David Heinemeier Hansson Added support for charsets for both subject and body. The default charse...
dhh authored
285 @@default_charset = "utf-8"
286 cattr_accessor :default_charset
287
100fd72 Jamis Buck Added a "content_type" accessor to allow messages to explicitly specify ...
jamis authored
288 @@default_content_type = "text/plain"
289 cattr_accessor :default_content_type
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
290
45b5555 Jamis Buck Make mime version default to 1.0. closes #2323
jamis authored
291 @@default_mime_version = "1.0"
dca4d4e Jamis Buck Multipart messages specify a MIME-Version header automatically #2003 [Jo...
jamis authored
292 cattr_accessor :default_mime_version
100fd72 Jamis Buck Added a "content_type" accessor to allow messages to explicitly specify ...
jamis authored
293
5c98152 Jamis Buck Better multipart support with implicit multipart/alternative and sorting...
jamis authored
294 @@default_implicit_parts_order = [ "text/html", "text/enriched", "text/plain" ]
295 cattr_accessor :default_implicit_parts_order
296
418c3f8 José Valim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
297 @@protected_instance_variables = []
81c416b José Valim More refactoring on ActionMailer::Base.
josevalim authored
298 cattr_reader :protected_instance_variables
28bf2fa Joshua Peek Protect body ivar from being clobbered by the mailer template assigns
josh authored
299
59f1df1 Jamis Buck Update/extend ActionMailer documentation (rdoc)
jamis authored
300 # Specify the BCC addresses for the message
301 adv_attr_accessor :bcc
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
302
59f1df1 Jamis Buck Update/extend ActionMailer documentation (rdoc)
jamis authored
303 # Specify the CC addresses for the message.
304 adv_attr_accessor :cc
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
305
59f1df1 Jamis Buck Update/extend ActionMailer documentation (rdoc)
jamis authored
306 # Specify the charset to use for the message. This defaults to the
307 # +default_charset+ specified for ActionMailer::Base.
308 adv_attr_accessor :charset
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
309
59f1df1 Jamis Buck Update/extend ActionMailer documentation (rdoc)
jamis authored
310 # Specify the content type for the message. This defaults to <tt>text/plain</tt>
311 # in most cases, but can be automatically set in some situations.
312 adv_attr_accessor :content_type
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
313
59f1df1 Jamis Buck Update/extend ActionMailer documentation (rdoc)
jamis authored
314 # Specify the from address for the message.
315 adv_attr_accessor :from
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
316
cf6299d Add ActionMailer#reply_to. [#245 state:resolved]
Adam authored
317 # Specify the address (if different than the "from" address) to direct
318 # replies to this message.
319 adv_attr_accessor :reply_to
320
59f1df1 Jamis Buck Update/extend ActionMailer documentation (rdoc)
jamis authored
321 # Specify additional headers to be added to the message.
322 adv_attr_accessor :headers
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
323
59f1df1 Jamis Buck Update/extend ActionMailer documentation (rdoc)
jamis authored
324 # Specify the order in which parts should be sorted, based on content-type.
325 # This defaults to the value for the +default_implicit_parts_order+.
326 adv_attr_accessor :implicit_parts_order
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
327
59f1df1 Jamis Buck Update/extend ActionMailer documentation (rdoc)
jamis authored
328 # Defaults to "1.0", but may be explicitly given if needed.
329 adv_attr_accessor :mime_version
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
330
59f1df1 Jamis Buck Update/extend ActionMailer documentation (rdoc)
jamis authored
331 # The recipient addresses for the message, either as a string (for a single
332 # address) or an array (for multiple addresses).
333 adv_attr_accessor :recipients
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
334
59f1df1 Jamis Buck Update/extend ActionMailer documentation (rdoc)
jamis authored
335 # The date on which the message was sent. If not set (the default), the
336 # header will be set by the delivery agent.
337 adv_attr_accessor :sent_on
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
338
59f1df1 Jamis Buck Update/extend ActionMailer documentation (rdoc)
jamis authored
339 # Specify the subject of the message.
340 adv_attr_accessor :subject
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
341
59f1df1 Jamis Buck Update/extend ActionMailer documentation (rdoc)
jamis authored
342 # Specify the template name to use for current message. This is the "base"
343 # template name, without the extension or directory, and may be used to
344 # have multiple mailer methods share the same template.
345 adv_attr_accessor :template
165097e David Heinemeier Hansson Added access to custom headers, like cc, bcc, and reply-to #268 [Andreas...
dhh authored
346
418c3f8 José Valim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
347 # The mail and action_name instances referenced by this mailer.
348 attr_reader :mail, :action_name
349
350 # Where the response body is stored.
351 attr_internal :response_body
352
bd5ed65 risk danger olson Update ActionMailer so it treats ActionView the same way that ActionCont...
technoweenie authored
353 # Override the mailer name, which defaults to an inflected version of the
354 # mailer's class name. If you want to use a template in a non-standard
355 # location, you can use this to specify that location.
418c3f8 José Valim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
356 attr_writer :mailer_name
357
bd5ed65 risk danger olson Update ActionMailer so it treats ActionView the same way that ActionCont...
technoweenie authored
358 def mailer_name(value = nil)
359 if value
418c3f8 José Valim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
360 @mailer_name = value
bd5ed65 risk danger olson Update ActionMailer so it treats ActionView the same way that ActionCont...
technoweenie authored
361 else
418c3f8 José Valim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
362 @mailer_name || self.class.mailer_name
bd5ed65 risk danger olson Update ActionMailer so it treats ActionView the same way that ActionCont...
technoweenie authored
363 end
364 end
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
365
418c3f8 José Valim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
366 # Alias controller_path to mailer_name so render :partial in views work.
367 alias :controller_path :mailer_name
43d5504 José Valim Move all render and layout pieces required in ActionMailer from ActionCo...
josevalim authored
368
539d9b3 Mikel Lindsaar More updates... 45 errors left to get it working with Mail gem
mikel authored
369 # Add a part to a multipart message, with the given content-type. The
370 # part itself is yielded to the block so that other properties (charset,
371 # body, headers, etc.) can be set on it.
15d7cac Mikel Lindsaar Starting again on actionmailer integration with mail
mikel authored
372 def part(params)
539d9b3 Mikel Lindsaar More updates... 45 errors left to get it working with Mail gem
mikel authored
373 params = {:content_type => params} if String === params
374 if custom_headers = params.delete(:headers)
375 STDERR.puts("Passing custom headers with :headers => {} is deprecated. Please just pass in custom headers directly.")
376 params = params.merge(custom_headers)
377 end
15d7cac Mikel Lindsaar Starting again on actionmailer integration with mail
mikel authored
378 part = Mail::Part.new(params)
539d9b3 Mikel Lindsaar More updates... 45 errors left to get it working with Mail gem
mikel authored
379 yield part if block_given?
380 @parts << part
381 end
382
383 # Add an attachment to a multipart message. This is simply a part with the
384 # content-disposition set to "attachment".
385 def attachment(params, &block)
386 params = { :content_type => params } if String === params
387 params = { :disposition => "attachment",
388 :transfer_encoding => "base64" }.merge(params)
389 part(params, &block)
15d7cac Mikel Lindsaar Starting again on actionmailer integration with mail
mikel authored
390 end
391
eda1719 Jamis Buck ActionMailer::Base.deliver(email) had been accidentally removed, but was...
jamis authored
392 class << self
bd5ed65 risk danger olson Update ActionMailer so it treats ActionView the same way that ActionCont...
technoweenie authored
393 attr_writer :mailer_name
394
81c416b José Valim More refactoring on ActionMailer::Base.
josevalim authored
395 delegate :settings, :settings=, :to => ActionMailer::DeliveryMethod::File, :prefix => :file
396 delegate :settings, :settings=, :to => ActionMailer::DeliveryMethod::Sendmail, :prefix => :sendmail
397 delegate :settings, :settings=, :to => ActionMailer::DeliveryMethod::Smtp, :prefix => :smtp
398
bd5ed65 risk danger olson Update ActionMailer so it treats ActionView the same way that ActionCont...
technoweenie authored
399 def mailer_name
400 @mailer_name ||= name.underscore
401 end
402
81c416b José Valim More refactoring on ActionMailer::Base.
josevalim authored
403 def delivery_method=(method_name)
404 @delivery_method = ActionMailer::DeliveryMethod.lookup_method(method_name)
405 end
406
3cf773b James Mead ActionMailer should respond_to? to methods handled by method_missing [#7...
floehopper authored
407 def respond_to?(method_symbol, include_private = false) #:nodoc:
408 matches_dynamic_method?(method_symbol) || super
409 end
410
411 def method_missing(method_symbol, *parameters) #:nodoc:
a62e9e9 Joel Chippindale Fix for ActionMailer::Base.method_missing so that it raises NoMethodErro...
mocoso authored
412 if match = matches_dynamic_method?(method_symbol)
413 case match[1]
414 when 'create' then new(match[2], *parameters).mail
415 when 'deliver' then new(match[2], *parameters).deliver!
416 when 'new' then nil
c65075f Joel Chippindale Fixed method_missing for ActionMailer so it no longer matches methods wh...
mocoso authored
417 else super
a62e9e9 Joel Chippindale Fix for ActionMailer::Base.method_missing so that it raises NoMethodErro...
mocoso authored
418 end
419 else
420 super
eda1719 Jamis Buck ActionMailer::Base.deliver(email) had been accidentally removed, but was...
jamis authored
421 end
422 end
423
59f1df1 Jamis Buck Update/extend ActionMailer documentation (rdoc)
jamis authored
424 # Receives a raw email, parses it into an email object, decodes it,
425 # instantiates a new mailer, and passes the email object to the mailer
98dc582 Pratik Merge docrails.
lifo authored
426 # object's +receive+ method. If you want your mailer to be able to
427 # process incoming messages, you'll need to implement a +receive+
59f1df1 Jamis Buck Update/extend ActionMailer documentation (rdoc)
jamis authored
428 # method that accepts the email object as a parameter:
429 #
430 # class MyMailer < ActionMailer::Base
431 # def receive(mail)
432 # ...
433 # end
434 # end
435 def receive(raw_email)
eda1719 Jamis Buck ActionMailer::Base.deliver(email) had been accidentally removed, but was...
jamis authored
436 logger.info "Received mail:\n #{raw_email}" unless logger.nil?
539d9b3 Mikel Lindsaar More updates... 45 errors left to get it working with Mail gem
mikel authored
437 mail = Mail.new(raw_email)
eda1719 Jamis Buck ActionMailer::Base.deliver(email) had been accidentally removed, but was...
jamis authored
438 new.receive(mail)
439 end
440
441 # Deliver the given mail object directly. This can be used to deliver
442 # a preconstructed mail object, like:
443 #
444 # email = MyMailer.create_some_mail(parameters)
445 # email.set_some_obscure_header "frobnicate"
446 # MyMailer.deliver(email)
447 def deliver(mail)
448 new.deliver!(mail)
449 end
271404e Jeremy Kemper Register alternative template engines using ActionMailer::Base.register_...
jeremy authored
450
cb21db1 Joshua Peek Treat ActionMailer template_root as a view path set internally to avoid ...
josh authored
451 def template_root
452 self.view_paths && self.view_paths.first
453 end
454
684c2dc José Valim Remove ActionMailer helpers and rely on AbstractController one.
josevalim authored
455 # Should template root overwrite the whole view_paths?
61c90a4 Michael Koziarski Reapply the TemplateFinder first applied in [8669] then reverted in [867...
NZKoz authored
456 def template_root=(root)
cb21db1 Joshua Peek Treat ActionMailer template_root as a view path set internally to avoid ...
josh authored
457 self.view_paths = ActionView::Base.process_view_paths(root)
61c90a4 Michael Koziarski Reapply the TemplateFinder first applied in [8669] then reverted in [867...
NZKoz authored
458 end
3cf773b James Mead ActionMailer should respond_to? to methods handled by method_missing [#7...
floehopper authored
459
460 private
461 def matches_dynamic_method?(method_name) #:nodoc:
462 method_name = method_name.to_s
c65075f Joel Chippindale Fixed method_missing for ActionMailer so it no longer matches methods wh...
mocoso authored
463 /^(create|deliver)_([_a-z]\w*)/.match(method_name) || /^(new)$/.match(method_name)
3cf773b James Mead ActionMailer should respond_to? to methods handled by method_missing [#7...
floehopper authored
464 end
eda1719 Jamis Buck ActionMailer::Base.deliver(email) had been accidentally removed, but was...
jamis authored
465 end
466
81c416b José Valim More refactoring on ActionMailer::Base.
josevalim authored
467 # Configure delivery method. Check ActionMailer::DeliveryMethod for more
468 # instructions.
469 superclass_delegating_reader :delivery_method
470 self.delivery_method = :smtp
471
359caef Jamis Buck A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
472 # Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer
473 # will be initialized according to the named method. If not, the mailer will
474 # remain uninitialized (useful when you only need to invoke the "receive"
475 # method, for instance).
2789b5d David Heinemeier Hansson Tuned documentation for release (AM)
dhh authored
476 def initialize(method_name=nil, *parameters) #:nodoc:
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
477 create!(method_name, *parameters) if method_name
359caef Jamis Buck A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
478 end
479
480 # Initialize the mailer via the given +method_name+. The body will be
15d7cac Mikel Lindsaar Starting again on actionmailer integration with mail
mikel authored
481 # rendered and a new Mail object created.
2789b5d David Heinemeier Hansson Tuned documentation for release (AM)
dhh authored
482 def create!(method_name, *parameters) #:nodoc:
43d5504 José Valim Move all render and layout pieces required in ActionMailer from ActionCo...
josevalim authored
483 initialize_defaults(method_name)
484 __send__(method_name, *parameters)
485
418c3f8 José Valim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
486 # Create e-mail parts
487 create_parts
09f798b José Valim Instrument create and deliver in ActionMailer.
josevalim authored
488
2aafdc8 José Valim Use I18n on ActionMailer subjects by default.
josevalim authored
489 # Set the subject if not set yet
490 @subject ||= I18n.t(method_name, :scope => [:actionmailer, :subjects, mailer_name],
491 :default => method_name.humanize)
43d5504 José Valim Move all render and layout pieces required in ActionMailer from ActionCo...
josevalim authored
492
493 # build the mail object itself
494 @mail = create_mail
359caef Jamis Buck A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
495 end
db045db David Heinemeier Hansson Initial
dhh authored
496
15d7cac Mikel Lindsaar Starting again on actionmailer integration with mail
mikel authored
497 # Delivers a Mail object. By default, it delivers the cached mail
98dc582 Pratik Merge docrails.
lifo authored
498 # object (from the <tt>create!</tt> method). If no cached mail object exists, and
eda1719 Jamis Buck ActionMailer::Base.deliver(email) had been accidentally removed, but was...
jamis authored
499 # no alternate has been given as the parameter, this will fail.
59f1df1 Jamis Buck Update/extend ActionMailer documentation (rdoc)
jamis authored
500 def deliver!(mail = @mail)
eda1719 Jamis Buck ActionMailer::Base.deliver(email) had been accidentally removed, but was...
jamis authored
501 raise "no mail object available for delivery!" unless mail
09f798b José Valim Instrument create and deliver in ActionMailer.
josevalim authored
502
43d5504 José Valim Move all render and layout pieces required in ActionMailer from ActionCo...
josevalim authored
503 if logger
be36455 Jeremy Kemper Ruby 1.9 compat: use Array() instead of #to_a.
jeremy authored
504 logger.info "Sent mail to #{Array(recipients).join(', ')}"
fbd3eb7 Jeremy Kemper Less verbose mail logging: just recipients for :info log level; the whol...
jeremy authored
505 logger.debug "\n#{mail.encoded}"
506 end
256e800 David Heinemeier Hansson Fixed quoting for all address headers, not just to #955 [Jamis Buck] Add...
dhh authored
507
2d7abe2 José Valim Renamed Orchestra to Notifications once again [#3321 state:resolved]
josevalim authored
508 ActiveSupport::Notifications.instrument(:deliver_mail, :mail => @mail) do
09f798b José Valim Instrument create and deliver in ActionMailer.
josevalim authored
509 begin
f4f7677 Matthew Rudy Jacobs abstract all of the ActionMailer delivery methods into their own classes...
matthewrudy authored
510 self.delivery_method.perform_delivery(mail) if perform_deliveries
09f798b José Valim Instrument create and deliver in ActionMailer.
josevalim authored
511 rescue Exception => e # Net::SMTP errors or sendmail pipe errors
512 raise e if raise_delivery_errors
513 end
359caef Jamis Buck A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
514 end
3fad0cd David Heinemeier Hansson Added support for charsets for both subject and body. The default charse...
dhh authored
515
09f798b José Valim Instrument create and deliver in ActionMailer.
josevalim authored
516 mail
359caef Jamis Buck A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
517 end
3fad0cd David Heinemeier Hansson Added support for charsets for both subject and body. The default charse...
dhh authored
518
359caef Jamis Buck A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
519 private
418c3f8 José Valim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
520
f474f33 Jamis Buck Move mailer initialization to a separate (overridable) method, so that s...
jamis authored
521 # Set up the default values for the various instance variables of this
522 # mailer. Subclasses may override this method to provide different
523 # defaults.
524 def initialize_defaults(method_name)
81c416b José Valim More refactoring on ActionMailer::Base.
josevalim authored
525 @charset ||= @@default_charset.dup
526 @content_type ||= @@default_content_type.dup
95e8740 David Heinemeier Hansson Allow Mailers to have custom initialize methods that set default instanc...
dhh authored
527 @implicit_parts_order ||= @@default_implicit_parts_order.dup
81c416b José Valim More refactoring on ActionMailer::Base.
josevalim authored
528 @mime_version ||= @@default_mime_version.dup if @@default_mime_version
529
530 @mailer_name ||= self.class.mailer_name
531 @template ||= method_name
532 @action_name = @template
533
534 @parts ||= []
95e8740 David Heinemeier Hansson Allow Mailers to have custom initialize methods that set default instanc...
dhh authored
535 @headers ||= {}
5fdc33c Matt Duncan Default sent_on time to now in ActionMailer
mrduncan authored
536 @sent_on ||= Time.now
f474f33 Jamis Buck Move mailer initialization to a separate (overridable) method, so that s...
jamis authored
537
418c3f8 José Valim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
538 super # Run deprecation hooks
6228220 David Heinemeier Hansson Revert "Revert "Add layout functionality to mailers.""
dhh authored
539 end
540
418c3f8 José Valim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
541 def create_parts
542 super # Run deprecation hooks
cb21db1 Joshua Peek Treat ActionMailer template_root as a view path set internally to avoid ...
josh authored
543
418c3f8 José Valim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
544 if String === response_body
15d7cac Mikel Lindsaar Starting again on actionmailer integration with mail
mikel authored
545 @parts.unshift Mail::Part.new(
546 :content_type => ["text", "plain", {:charset => charset}],
547 :content_disposition => "inline",
418c3f8 José Valim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
548 :body => response_body
549 )
550 else
551 self.class.template_root.find_all(@template, {}, mailer_name).each do |template|
15d7cac Mikel Lindsaar Starting again on actionmailer integration with mail
mikel authored
552 ct = template.mime_type ? template.mime_type.to_s : "text/plain"
553 main_type, sub_type = ct.split("/")
554 @parts << Mail::Part.new(
555 :content_type => [main_type, sub_type, {:charset => charset}],
556 :content_disposition => "inline",
418c3f8 José Valim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
557 :body => render_to_body(:_template => template)
558 )
559 end
cb21db1 Joshua Peek Treat ActionMailer template_root as a view path set internally to avoid ...
josh authored
560
418c3f8 José Valim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
561 if @parts.size > 1
562 @content_type = "multipart/alternative" if @content_type !~ /^multipart/
563 @parts = sort_parts(@parts, @implicit_parts_order)
564 end
2aafdc8 José Valim Use I18n on ActionMailer subjects by default.
josevalim authored
565
566 # If this is a multipart e-mail add the mime_version if it is not
567 # already set.
568 @mime_version ||= "1.0" if !@parts.empty?
418c3f8 José Valim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
569 end
db045db David Heinemeier Hansson Initial
dhh authored
570 end
571
5c98152 Jamis Buck Better multipart support with implicit multipart/alternative and sorting...
jamis authored
572 def sort_parts(parts, order = [])
573 order = order.collect { |s| s.downcase }
418c3f8 José Valim Another refactoring on AM. body is deprecated, use render instead.
josevalim authored
574
5c98152 Jamis Buck Better multipart support with implicit multipart/alternative and sorting...
jamis authored
575 parts = parts.sort do |a, b|
15d7cac Mikel Lindsaar Starting again on actionmailer integration with mail
mikel authored
576 a_ct = a.content_type.content_type.downcase
577 b_ct = b.content_type.content_type.downcase
5c98152 Jamis Buck Better multipart support with implicit multipart/alternative and sorting...
jamis authored
578
579 a_in = order.include? a_ct
580 b_in = order.include? b_ct
581
582 s = case
583 when a_in && b_in
584 order.index(a_ct) <=> order.index(b_ct)
585 when a_in
586 -1
587 when b_in
588 1
589 else
590 a_ct <=> b_ct
591 end
592
593 # reverse the ordering because parts that come last are displayed
594 # first in mail clients
595 (s * -1)
596 end
597
598 parts
599 end
600
359caef Jamis Buck A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
601 def create_mail
15d7cac Mikel Lindsaar Starting again on actionmailer integration with mail
mikel authored
602 m = Mail.new
74a612c David Heinemeier Hansson Added that delivery errors are caught in a way so the mail is still retu...
dhh authored
603
cf6299d Add ActionMailer#reply_to. [#245 state:resolved]
Adam authored
604 m.subject, = quote_any_if_necessary(charset, subject)
605 m.to, m.from = quote_any_address_if_necessary(charset, recipients, from)
606 m.bcc = quote_address_if_necessary(bcc, charset) unless bcc.nil?
607 m.cc = quote_address_if_necessary(cc, charset) unless cc.nil?
608 m.reply_to = quote_address_if_necessary(reply_to, charset) unless reply_to.nil?
dca4d4e Jamis Buck Multipart messages specify a MIME-Version header automatically #2003 [Jo...
jamis authored
609 m.mime_version = mime_version unless mime_version.nil?
cf6299d Add ActionMailer#reply_to. [#245 state:resolved]
Adam authored
610 m.date = sent_on.to_time rescue sent_on if sent_on
611
359caef Jamis Buck A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
612 headers.each { |k, v| m[k] = v }
db045db David Heinemeier Hansson Initial
dhh authored
613
db0e8ff Jamis Buck Parse content-type apart before using it so that sub-parts of the header...
jamis authored
614 real_content_type, ctype_attrs = parse_content_type
8b340ab José Valim Revert "Rename Orchestra to Notifications [#3321 state:resolved]"
josevalim authored
615
359caef Jamis Buck A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
616 if @parts.empty?
539d9b3 Mikel Lindsaar More updates... 45 errors left to get it working with Mail gem
mikel authored
617 main_type, sub_type = split_content_type(real_content_type)
618 m.content_type(main_type, sub_type, ctype_attrs)
e201fc7 Joshua Peek use autoload instead of explicit requires for ActionMailer
josh authored
619 m.body = normalize_new_lines(body)
0a132c2 Refactor ActionView::Path
Yehuda Katz + Carl Lerche authored
620 elsif @parts.size == 1 && @parts.first.parts.empty?
539d9b3 Mikel Lindsaar More updates... 45 errors left to get it working with Mail gem
mikel authored
621 main_type, sub_type = split_content_type(real_content_type)
622 m.content_type(main_type, sub_type, ctype_attrs)
0a132c2 Refactor ActionView::Path
Yehuda Katz + Carl Lerche authored
623 m.body = normalize_new_lines(@parts.first.body)
359caef Jamis Buck A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
624 else
625 @parts.each do |p|
539d9b3 Mikel Lindsaar More updates... 45 errors left to get it working with Mail gem
mikel authored
626 m.parts << p
359caef Jamis Buck A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
627 end
3b0e1d9 Joshua Peek Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
628
49efa02 Jamis Buck Nil charset caused subject line to be improperly quoted in implicitly mu...
jamis authored
629 if real_content_type =~ /multipart/
630 ctype_attrs.delete "charset"
539d9b3 Mikel Lindsaar More updates... 45 errors left to get it working with Mail gem
mikel authored
631 main_type, sub_type = split_content_type(real_content_type)
632 m.content_type([main_type.to_s, sub_type.to_s, ctype_attrs])
49efa02 Jamis Buck Nil charset caused subject line to be improperly quoted in implicitly mu...
jamis authored
633 end
359caef Jamis Buck A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
634 end
256e800 David Heinemeier Hansson Fixed quoting for all address headers, not just to #955 [Jamis Buck] Add...
dhh authored
635
359caef Jamis Buck A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
636 @mail = m
256e800 David Heinemeier Hansson Fixed quoting for all address headers, not just to #955 [Jamis Buck] Add...
dhh authored
637 end
539d9b3 Mikel Lindsaar More updates... 45 errors left to get it working with Mail gem
mikel authored
638
639 def split_content_type(ct)
640 ct.to_s.split("/")
641 end
256e800 David Heinemeier Hansson Fixed quoting for all address headers, not just to #955 [Jamis Buck] Add...
dhh authored
642
15d7cac Mikel Lindsaar Starting again on actionmailer integration with mail
mikel authored
643 def parse_content_type(defaults=nil)
644 if content_type.blank?
645 return defaults ?
646 [ defaults.content_type, { 'charset' => defaults.charset } ] :
647 [ nil, {} ]
648 end
649 ctype, *attrs = content_type.split(/;\s*/)
650 attrs = attrs.inject({}) { |h,s| k,v = s.split(/=/, 2); h[k] = v; h }
651 [ctype, {"charset" => charset || defaults && defaults.charset}.merge(attrs)]
652 end
653
654
db045db David Heinemeier Hansson Initial
dhh authored
655 end
656 end
Something went wrong with that request. Please try again.