Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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