Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 658 lines (582 sloc) 26.772 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.
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored
219 # * <tt>:authentication</tt> - If your mail server requires authentication, you need to specify the authentication type here.
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 #
46f30f9 @lifo Merge documentation changes from docrails.
lifo 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
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
46f30f9 @lifo Merge documentation changes from docrails.
lifo authored
239 # can also pick a different content type from inside a method with +content_type+.
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
271404e @jeremy Register alternative template engines using ActionMailer::Base.register_...
jeremy authored
256 cattr_accessor :template_extensions
257 @@template_extensions = ['erb', 'builder', 'rhtml', 'rxml']
258
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
259 @@smtp_settings = {
260 :address => "localhost",
261 :port => 25,
262 :domain => 'localhost.localdomain',
263 :user_name => nil,
264 :password => nil,
db045db @dhh Initial
dhh authored
265 :authentication => nil
266 }
27bb903 @NZKoz Rename server_settings to smtp_settings, add sendmail_settings to allow...
NZKoz authored
267 cattr_accessor :smtp_settings
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
268
27bb903 @NZKoz Rename server_settings to smtp_settings, add sendmail_settings to allow...
NZKoz authored
269 @@sendmail_settings = {
270 :location => '/usr/sbin/sendmail',
271 :arguments => '-i -t'
272 }
273 cattr_accessor :sendmail_settings
db045db @dhh Initial
dhh authored
274
275 @@raise_delivery_errors = true
276 cattr_accessor :raise_delivery_errors
277
57cde63 @dhh Allow ActionMailer subclasses to individually set their delivery method ...
dhh authored
278 superclass_delegating_accessor :delivery_method
279 self.delivery_method = :smtp
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
280
db045db @dhh Initial
dhh authored
281 @@perform_deliveries = true
282 cattr_accessor :perform_deliveries
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
283
db045db @dhh Initial
dhh authored
284 @@deliveries = []
285 cattr_accessor :deliveries
286
3fad0cd @dhh Added support for charsets for both subject and body. The default charse...
dhh authored
287 @@default_charset = "utf-8"
288 cattr_accessor :default_charset
289
100fd72 @jamis Added a "content_type" accessor to allow messages to explicitly specify ...
jamis authored
290 @@default_content_type = "text/plain"
291 cattr_accessor :default_content_type
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
292
45b5555 @jamis Make mime version default to 1.0. closes #2323
jamis authored
293 @@default_mime_version = "1.0"
dca4d4e @jamis Multipart messages specify a MIME-Version header automatically #2003 [Jo...
jamis authored
294 cattr_accessor :default_mime_version
100fd72 @jamis Added a "content_type" accessor to allow messages to explicitly specify ...
jamis authored
295
5c98152 @jamis Better multipart support with implicit multipart/alternative and sorting...
jamis authored
296 @@default_implicit_parts_order = [ "text/html", "text/enriched", "text/plain" ]
297 cattr_accessor :default_implicit_parts_order
298
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
299 # Specify the BCC addresses for the message
300 adv_attr_accessor :bcc
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
301
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
302 # Define the body of the message. This is either a Hash (in which case it
303 # specifies the variables to pass to the template when it is rendered),
304 # or a string, in which case it specifies the actual text of the message.
305 adv_attr_accessor :body
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 CC addresses for the message.
308 adv_attr_accessor :cc
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
309
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
310 # Specify the charset to use for the message. This defaults to the
311 # +default_charset+ specified for ActionMailer::Base.
312 adv_attr_accessor :charset
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
313
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
314 # Specify the content type for the message. This defaults to <tt>text/plain</tt>
315 # in most cases, but can be automatically set in some situations.
316 adv_attr_accessor :content_type
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
317
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
318 # Specify the from address for the message.
319 adv_attr_accessor :from
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
320
cf6299d Add ActionMailer#reply_to. [#245 state:resolved]
Adam authored
321 # Specify the address (if different than the "from" address) to direct
322 # replies to this message.
323 adv_attr_accessor :reply_to
324
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
325 # Specify additional headers to be added to the message.
326 adv_attr_accessor :headers
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
327
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
328 # Specify the order in which parts should be sorted, based on content-type.
329 # This defaults to the value for the +default_implicit_parts_order+.
330 adv_attr_accessor :implicit_parts_order
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 # Defaults to "1.0", but may be explicitly given if needed.
333 adv_attr_accessor :mime_version
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
334
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
335 # The recipient addresses for the message, either as a string (for a single
336 # address) or an array (for multiple addresses).
337 adv_attr_accessor :recipients
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
338
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
339 # The date on which the message was sent. If not set (the default), the
340 # header will be set by the delivery agent.
341 adv_attr_accessor :sent_on
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 subject of the message.
344 adv_attr_accessor :subject
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
345
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
346 # Specify the template name to use for current message. This is the "base"
347 # template name, without the extension or directory, and may be used to
348 # have multiple mailer methods share the same template.
349 adv_attr_accessor :template
165097e @dhh Added access to custom headers, like cc, bcc, and reply-to #268 [Andreas...
dhh authored
350
bd5ed65 @technoweenie Update ActionMailer so it treats ActionView the same way that ActionCont...
technoweenie authored
351 # Override the mailer name, which defaults to an inflected version of the
352 # mailer's class name. If you want to use a template in a non-standard
353 # location, you can use this to specify that location.
354 def mailer_name(value = nil)
355 if value
356 self.mailer_name = value
357 else
358 self.class.mailer_name
359 end
360 end
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
361
bd5ed65 @technoweenie Update ActionMailer so it treats ActionView the same way that ActionCont...
technoweenie authored
362 def mailer_name=(value)
363 self.class.mailer_name = value
364 end
365
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
366 # The mail object instance referenced by this mailer.
367 attr_reader :mail
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
368
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but was...
jamis authored
369 class << self
bd5ed65 @technoweenie Update ActionMailer so it treats ActionView the same way that ActionCont...
technoweenie authored
370 attr_writer :mailer_name
371
372 def mailer_name
373 @mailer_name ||= name.underscore
374 end
375
376 # for ActionView compatibility
377 alias_method :controller_name, :mailer_name
378 alias_method :controller_path, :mailer_name
379
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but was...
jamis authored
380 def method_missing(method_symbol, *parameters)#:nodoc:
381 case method_symbol.id2name
382 when /^create_([_a-z]\w*)/ then new($1, *parameters).mail
383 when /^deliver_([_a-z]\w*)/ then new($1, *parameters).deliver!
384 when "new" then nil
385 else super
386 end
387 end
388
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
389 # Receives a raw email, parses it into an email object, decodes it,
390 # instantiates a new mailer, and passes the email object to the mailer
98dc582 @lifo Merge docrails.
lifo authored
391 # object's +receive+ method. If you want your mailer to be able to
392 # process incoming messages, you'll need to implement a +receive+
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
393 # method that accepts the email object as a parameter:
394 #
395 # class MyMailer < ActionMailer::Base
396 # def receive(mail)
397 # ...
398 # end
399 # end
400 def receive(raw_email)
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but was...
jamis authored
401 logger.info "Received mail:\n #{raw_email}" unless logger.nil?
402 mail = TMail::Mail.parse(raw_email)
403 mail.base64_decode
404 new.receive(mail)
405 end
406
407 # Deliver the given mail object directly. This can be used to deliver
408 # a preconstructed mail object, like:
409 #
410 # email = MyMailer.create_some_mail(parameters)
411 # email.set_some_obscure_header "frobnicate"
412 # MyMailer.deliver(email)
413 def deliver(mail)
414 new.deliver!(mail)
415 end
271404e @jeremy Register alternative template engines using ActionMailer::Base.register_...
jeremy authored
416
417 # Register a template extension so mailer templates written in a
418 # templating language other than rhtml or rxml are supported.
419 # To use this, include in your template-language plugin's init
420 # code or on a per-application basis, this can be invoked from
dc4eec1 @lifo Merge docrails:
lifo authored
421 # <tt>config/environment.rb</tt>:
271404e @jeremy Register alternative template engines using ActionMailer::Base.register_...
jeremy authored
422 #
423 # ActionMailer::Base.register_template_extension('haml')
424 def register_template_extension(extension)
425 template_extensions << extension
426 end
61c90a4 @NZKoz Reapply the TemplateFinder first applied in [8669] then reverted in [867...
NZKoz authored
427
cb21db1 @josh Treat ActionMailer template_root as a view path set internally to avoid ...
josh authored
428 def template_root
429 self.view_paths && self.view_paths.first
430 end
431
61c90a4 @NZKoz Reapply the TemplateFinder first applied in [8669] then reverted in [867...
NZKoz authored
432 def template_root=(root)
cb21db1 @josh Treat ActionMailer template_root as a view path set internally to avoid ...
josh authored
433 self.view_paths = ActionView::Base.process_view_paths(root)
61c90a4 @NZKoz Reapply the TemplateFinder first applied in [8669] then reverted in [867...
NZKoz authored
434 end
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but was...
jamis authored
435 end
436
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
437 # Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer
438 # will be initialized according to the named method. If not, the mailer will
439 # remain uninitialized (useful when you only need to invoke the "receive"
440 # method, for instance).
2789b5d @dhh Tuned documentation for release (AM)
dhh authored
441 def initialize(method_name=nil, *parameters) #:nodoc:
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
442 create!(method_name, *parameters) if method_name
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
443 end
444
445 # Initialize the mailer via the given +method_name+. The body will be
446 # rendered and a new TMail::Mail object created.
2789b5d @dhh Tuned documentation for release (AM)
dhh authored
447 def create!(method_name, *parameters) #:nodoc:
f474f33 @jamis Move mailer initialization to a separate (overridable) method, so that s...
jamis authored
448 initialize_defaults(method_name)
c3ff04b @jeremy Allow mailer actions named send by using __send__ internally. Closes #64...
jeremy authored
449 __send__(method_name, *parameters)
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
450
451 # If an explicit, textual body has not been set, we check assumptions.
452 unless String === @body
453 # First, we look to see if there are any likely templates that match,
454 # which include the content-type in their file name (i.e.,
21187c0 @dhh Apply the rest of Chads patch
dhh authored
455 # "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
456 # have not already been specified manually.
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
457 if @parts.empty?
813a8b9 @jamis Allow template to be explicitly specified #1448 [tuxie@dekadance.se]
jamis authored
458 templates = Dir.glob("#{template_path}/#{@template}.*")
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
459 templates.each do |path|
797de4d @jamis Use the full template file name for implicitly selected templates, inste...
jamis authored
460 basename = File.basename(path)
271404e @jeremy Register alternative template engines using ActionMailer::Base.register_...
jeremy authored
461 template_regex = Regexp.new("^([^\\\.]+)\\\.([^\\\.]+\\\.[^\\\.]+)\\\.(" + template_extensions.join('|') + ")$")
462 next unless md = template_regex.match(basename)
797de4d @jamis Use the full template file name for implicitly selected templates, inste...
jamis authored
463 template_name = basename
f2ee215 @jeremy Stricter matching for implicitly multipart filenames excludes files endi...
jeremy authored
464 content_type = md.captures[1].gsub('.', '/')
465 @parts << Part.new(:content_type => content_type,
053cb22 @jamis Use the real charset for parts generated by a template, instead of the s...
jamis authored
466 :disposition => "inline", :charset => charset,
f3aa7c1 @jeremy r4730@asus: jeremy | 2006-06-29 13:13:38 -0700
jeremy authored
467 :body => render_message(template_name, @body))
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
468 end
5c98152 @jamis Better multipart support with implicit multipart/alternative and sorting...
jamis authored
469 unless @parts.empty?
470 @content_type = "multipart/alternative"
471 @parts = sort_parts(@parts, @implicit_parts_order)
472 end
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
473 end
db045db @dhh Initial
dhh authored
474
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
475 # Then, if there were such templates, we check to see if we ought to
476 # also render a "normal" template (without the content type). If a
477 # normal template exists (or if there were no implicit parts) we render
478 # it.
479 template_exists = @parts.empty?
34df9be @jamis Template paths with dot chars in them no longer mess up implicit templat...
jamis authored
480 template_exists ||= Dir.glob("#{template_path}/#{@template}.*").any? { |i| File.basename(i).split(".").length == 2 }
f3aa7c1 @jeremy r4730@asus: jeremy | 2006-06-29 13:13:38 -0700
jeremy authored
481 @body = render_message(@template, @body) if template_exists
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
482
483 # Finally, if there are other message parts and a textual body exists,
484 # we shift it onto the front of the parts and set the body to nil (so
485 # that create_mail doesn't try to render it in addition to the parts).
486 if !@parts.empty? && String === @body
487 @parts.unshift Part.new(:charset => charset, :body => @body)
488 @body = nil
425aa50 @dhh Added receiver method for incoming email
dhh authored
489 end
db045db @dhh Initial
dhh authored
490 end
491
dca4d4e @jamis Multipart messages specify a MIME-Version header automatically #2003 [Jo...
jamis authored
492 # If this is a multipart e-mail add the mime_version if it is not
493 # already set.
494 @mime_version ||= "1.0" if !@parts.empty?
495
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
496 # build the mail object itself
497 @mail = create_mail
498 end
db045db @dhh Initial
dhh authored
499
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but was...
jamis authored
500 # Delivers a TMail::Mail object. By default, it delivers the cached mail
98dc582 @lifo Merge docrails.
lifo authored
501 # 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
502 # no alternate has been given as the parameter, this will fail.
59f1df1 @jamis Update/extend ActionMailer documentation (rdoc)
jamis authored
503 def deliver!(mail = @mail)
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but was...
jamis authored
504 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
505 unless logger.nil?
be36455 @jeremy Ruby 1.9 compat: use Array() instead of #to_a.
jeremy authored
506 logger.info "Sent mail to #{Array(recipients).join(', ')}"
fbd3eb7 @jeremy Less verbose mail logging: just recipients for :info log level; the whol...
jeremy authored
507 logger.debug "\n#{mail.encoded}"
508 end
256e800 @dhh Fixed quoting for all address headers, not just to #955 [Jamis Buck] Add...
dhh authored
509
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
510 begin
c3ff04b @jeremy Allow mailer actions named send by using __send__ internally. Closes #64...
jeremy authored
511 __send__("perform_delivery_#{delivery_method}", mail) if perform_deliveries
12ff554 @jeremy Tighten rescue clauses. Closes #5985.
jeremy authored
512 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
513 raise e if raise_delivery_errors
514 end
3fad0cd @dhh Added support for charsets for both subject and body. The default charse...
dhh authored
515
eda1719 @jamis ActionMailer::Base.deliver(email) had been accidentally removed, but was...
jamis authored
516 return mail
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
517 end
3fad0cd @dhh Added support for charsets for both subject and body. The default charse...
dhh authored
518
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
519 private
f474f33 @jamis Move mailer initialization to a separate (overridable) method, so that s...
jamis authored
520 # Set up the default values for the various instance variables of this
521 # mailer. Subclasses may override this method to provide different
522 # defaults.
523 def initialize_defaults(method_name)
95e8740 @dhh Allow Mailers to have custom initialize methods that set default instanc...
dhh authored
524 @charset ||= @@default_charset.dup
525 @content_type ||= @@default_content_type.dup
526 @implicit_parts_order ||= @@default_implicit_parts_order.dup
527 @template ||= method_name
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
528 @mailer_name ||= self.class.name.underscore
95e8740 @dhh Allow Mailers to have custom initialize methods that set default instanc...
dhh authored
529 @parts ||= []
530 @headers ||= {}
531 @body ||= {}
dca4d4e @jamis Multipart messages specify a MIME-Version header automatically #2003 [Jo...
jamis authored
532 @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
533 end
534
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
535 def render_message(method_name, body)
7461227 @josh Ruby 1.9: Call join on template_root instead of to_s
josh authored
536 render :file => method_name, :body => body
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
537 end
ae1e852 @jamis Add a unified render method to ActionMailer (delegates to ActionView::Ba...
jamis authored
538
539 def render(opts)
540 body = opts.delete(:body)
bd5ed65 @technoweenie Update ActionMailer so it treats ActionView the same way that ActionCont...
technoweenie authored
541 if opts[:file] && opts[:file] !~ /\//
542 opts[:file] = "#{mailer_name}/#{opts[:file]}"
543 end
ae1e852 @jamis Add a unified render method to ActionMailer (delegates to ActionView::Ba...
jamis authored
544 initialize_template_class(body).render(opts)
545 end
546
cb21db1 @josh Treat ActionMailer template_root as a view path set internally to avoid ...
josh authored
547 def template_root
548 self.class.template_root
549 end
550
551 def template_root=(root)
552 self.class.template_root = root
553 end
554
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
555 def template_path
e23156e @josh Only create a path for ActionMailer template root instead of a path set....
josh authored
556 "#{template_root}/#{mailer_name}"
db045db @dhh Initial
dhh authored
557 end
558
5ec990a @jamis Helper support for ActionMailer
jamis authored
559 def initialize_template_class(assigns)
cb21db1 @josh Treat ActionMailer template_root as a view path set internally to avoid ...
josh authored
560 ActionView::Base.new(view_paths, assigns, self)
5ec990a @jamis Helper support for ActionMailer
jamis authored
561 end
562
5c98152 @jamis Better multipart support with implicit multipart/alternative and sorting...
jamis authored
563 def sort_parts(parts, order = [])
564 order = order.collect { |s| s.downcase }
565
566 parts = parts.sort do |a, b|
567 a_ct = a.content_type.downcase
568 b_ct = b.content_type.downcase
569
570 a_in = order.include? a_ct
571 b_in = order.include? b_ct
572
573 s = case
574 when a_in && b_in
575 order.index(a_ct) <=> order.index(b_ct)
576 when a_in
577 -1
578 when b_in
579 1
580 else
581 a_ct <=> b_ct
582 end
583
584 # reverse the ordering because parts that come last are displayed
585 # first in mail clients
586 (s * -1)
587 end
588
589 parts
590 end
591
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
592 def create_mail
593 m = TMail::Mail.new
74a612c @dhh Added that delivery errors are caught in a way so the mail is still retu...
dhh authored
594
cf6299d Add ActionMailer#reply_to. [#245 state:resolved]
Adam authored
595 m.subject, = quote_any_if_necessary(charset, subject)
596 m.to, m.from = quote_any_address_if_necessary(charset, recipients, from)
597 m.bcc = quote_address_if_necessary(bcc, charset) unless bcc.nil?
598 m.cc = quote_address_if_necessary(cc, charset) unless cc.nil?
599 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
600 m.mime_version = mime_version unless mime_version.nil?
cf6299d Add ActionMailer#reply_to. [#245 state:resolved]
Adam authored
601 m.date = sent_on.to_time rescue sent_on if sent_on
602
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
603 headers.each { |k, v| m[k] = v }
db045db @dhh Initial
dhh authored
604
db0e8ff @jamis Parse content-type apart before using it so that sub-parts of the header...
jamis authored
605 real_content_type, ctype_attrs = parse_content_type
606
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
607 if @parts.empty?
db0e8ff @jamis Parse content-type apart before using it so that sub-parts of the header...
jamis authored
608 m.set_content_type(real_content_type, nil, ctype_attrs)
bde3df2 @jamis Correctly normalize newlines in outgoing emails before encoding the body...
jamis authored
609 m.body = Utils.normalize_new_lines(body)
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
610 else
611 if String === body
612 part = TMail::Mail.new
bde3df2 @jamis Correctly normalize newlines in outgoing emails before encoding the body...
jamis authored
613 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
614 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
615 part.set_content_disposition "inline"
616 m.parts << part
617 end
3fad0cd @dhh Added support for charsets for both subject and body. The default charse...
dhh authored
618
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
619 @parts.each do |p|
620 part = (TMail::Mail === p ? p : p.to_mail(self))
621 m.parts << part
622 end
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
623
49efa02 @jamis Nil charset caused subject line to be improperly quoted in implicitly mu...
jamis authored
624 if real_content_type =~ /multipart/
625 ctype_attrs.delete "charset"
626 m.set_content_type(real_content_type, nil, ctype_attrs)
627 end
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
628 end
256e800 @dhh Fixed quoting for all address headers, not just to #955 [Jamis Buck] Add...
dhh authored
629
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
630 @mail = m
256e800 @dhh Fixed quoting for all address headers, not just to #955 [Jamis Buck] Add...
dhh authored
631 end
632
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
633 def perform_delivery_smtp(mail)
508c26c @jamis BCC headers are removed when sending via SMTP
jamis authored
634 destinations = mail.destinations
635 mail.ready_to_send
5c0d38f @dhh Fixed that a return-path header would be ignored (closes #7572) [joost]
dhh authored
636 sender = mail['return-path'] || mail.from
508c26c @jamis BCC headers are removed when sending via SMTP
jamis authored
637
3b0e1d9 @josh Prefer string core_ext inflector methods over directly accessing Inflect...
josh authored
638 Net::SMTP.start(smtp_settings[:address], smtp_settings[:port], smtp_settings[:domain],
416091d @NZKoz Fix missed smtp_session changes to base.rb.
NZKoz authored
639 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
640 smtp.sendmail(mail.encoded, sender, destinations)
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
641 end
256e800 @dhh Fixed quoting for all address headers, not just to #955 [Jamis Buck] Add...
dhh authored
642 end
643
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
644 def perform_delivery_sendmail(mail)
77730f7 @NZKoz Avoid modifying the sendmail_settings hash when using the return path. C...
NZKoz authored
645 sendmail_args = sendmail_settings[:arguments]
646 sendmail_args += " -f \"#{mail['return-path']}\"" if mail['return-path']
647 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
648 sm.print(mail.encoded.gsub(/\r/, ''))
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
649 sm.flush
256e800 @dhh Fixed quoting for all address headers, not just to #955 [Jamis Buck] Add...
dhh authored
650 end
651 end
652
359caef @jamis A very thorough refactoring, resulting in new mail property setters and ...
jamis authored
653 def perform_delivery_test(mail)
654 deliveries << mail
655 end
db045db @dhh Initial
dhh authored
656 end
657 end
Something went wrong with that request. Please try again.