|
| 1 | +require 'tmpdir' |
| 2 | + |
1 | 3 | require "active_support/core_ext/class"
|
2 | 4 | # Use the old layouts until actionmailer gets refactored
|
3 | 5 | require "action_controller/legacy/layout"
|
@@ -224,9 +226,13 @@ module ActionMailer #:nodoc:
|
224 | 226 | # * <tt>:location</tt> - The location of the sendmail executable. Defaults to <tt>/usr/sbin/sendmail</tt>.
|
225 | 227 | # * <tt>:arguments</tt> - The command line arguments. Defaults to <tt>-i -t</tt>.
|
226 | 228 | #
|
| 229 | + # * <tt>file_settings</tt> - Allows you to override options for the <tt>:file</tt> delivery method. |
| 230 | + # * <tt>:location</tt> - The directory into which emails will be written. Defaults to the application <tt>tmp/mails</tt>. |
| 231 | + # |
227 | 232 | # * <tt>raise_delivery_errors</tt> - Whether or not errors should be raised if the email fails to be delivered.
|
228 | 233 | #
|
229 |
| - # * <tt>delivery_method</tt> - Defines a delivery method. Possible values are <tt>:smtp</tt> (default), <tt>:sendmail</tt>, and <tt>:test</tt>. |
| 234 | + # * <tt>delivery_method</tt> - Defines a delivery method. Possible values are <tt>:smtp</tt> (default), <tt>:sendmail</tt>, <tt>:test</tt>, |
| 235 | + # and <tt>:file</tt>. |
230 | 236 | #
|
231 | 237 | # * <tt>perform_deliveries</tt> - Determines whether <tt>deliver_*</tt> methods are actually carried out. By default they are,
|
232 | 238 | # but this can be turned off to help functional testing.
|
@@ -279,6 +285,12 @@ class Base
|
279 | 285 | }
|
280 | 286 | cattr_accessor :sendmail_settings
|
281 | 287 |
|
| 288 | + @@file_settings = { |
| 289 | + :location => defined?(Rails) ? "#{Rails.root}/tmp/mails" : "#{Dir.tmpdir}/mails" |
| 290 | + } |
| 291 | + |
| 292 | + cattr_accessor :file_settings |
| 293 | + |
282 | 294 | @@raise_delivery_errors = true
|
283 | 295 | cattr_accessor :raise_delivery_errors
|
284 | 296 |
|
@@ -724,6 +736,14 @@ def perform_delivery_sendmail(mail)
|
724 | 736 | def perform_delivery_test(mail)
|
725 | 737 | deliveries << mail
|
726 | 738 | end
|
| 739 | + |
| 740 | + def perform_delivery_file(mail) |
| 741 | + FileUtils.mkdir_p file_settings[:location] |
| 742 | + |
| 743 | + (mail.to + mail.cc + mail.bcc).uniq.each do |to| |
| 744 | + File.open(File.join(file_settings[:location], to), 'a') { |f| f.write(mail) } |
| 745 | + end |
| 746 | + end |
727 | 747 | end
|
728 | 748 |
|
729 | 749 | Base.class_eval do
|
|
0 commit comments