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