Skip to content

HTTPS clone URL

Subversion checkout URL

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