diff options
author | Eric Davis <edavis@littlestreamsoftware.com> | 2009-08-07 20:56:54 -0700 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2009-08-08 16:32:17 +1200 |
commit | fbe6c3c19553fd05edc904af62fbfc8aee1d907d (patch) | |
tree | dab8152b9c8b0c0afa5c78682044ef41adb18135 /actionmailer/lib/action_mailer | |
parent | 54e7f5ba435b7573c68c7acd65c9d2537427de7e (diff) | |
download | rails-fbe6c3c19553fd05edc904af62fbfc8aee1d907d.tar.gz rails-fbe6c3c19553fd05edc904af62fbfc8aee1d907d.tar.bz2 rails-fbe6c3c19553fd05edc904af62fbfc8aee1d907d.zip |
Adds a :file delivery_method to save email to a file on disk
Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#2438 state:committed]
Diffstat (limited to 'actionmailer/lib/action_mailer')
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index d01f561f50..5ecefe7c09 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -1,3 +1,5 @@ +require 'tmpdir' + require "active_support/core_ext/class" # Use the old layouts until actionmailer gets refactored require "action_controller/legacy/layout" @@ -224,9 +226,13 @@ module ActionMailer #:nodoc: # * <tt>:location</tt> - The location of the sendmail executable. Defaults to <tt>/usr/sbin/sendmail</tt>. # * <tt>:arguments</tt> - The command line arguments. Defaults to <tt>-i -t</tt>. # + # * <tt>file_settings</tt> - Allows you to override options for the <tt>:file</tt> delivery method. + # * <tt>:location</tt> - The directory into which emails will be written. Defaults to the application <tt>tmp/mails</tt>. + # # * <tt>raise_delivery_errors</tt> - Whether or not errors should be raised if the email fails to be delivered. # - # * <tt>delivery_method</tt> - Defines a delivery method. Possible values are <tt>:smtp</tt> (default), <tt>:sendmail</tt>, and <tt>:test</tt>. + # * <tt>delivery_method</tt> - Defines a delivery method. Possible values are <tt>:smtp</tt> (default), <tt>:sendmail</tt>, <tt>:test</tt>, + # and <tt>:file</tt>. # # * <tt>perform_deliveries</tt> - Determines whether <tt>deliver_*</tt> methods are actually carried out. By default they are, # but this can be turned off to help functional testing. @@ -279,6 +285,12 @@ module ActionMailer #:nodoc: } cattr_accessor :sendmail_settings + @@file_settings = { + :location => defined?(Rails) ? "#{Rails.root}/tmp/mails" : "#{Dir.tmpdir}/mails" + } + + cattr_accessor :file_settings + @@raise_delivery_errors = true cattr_accessor :raise_delivery_errors @@ -724,6 +736,14 @@ module ActionMailer #:nodoc: def perform_delivery_test(mail) deliveries << mail end + + def perform_delivery_file(mail) + FileUtils.mkdir_p file_settings[:location] + + (mail.to + mail.cc + mail.bcc).uniq.each do |to| + File.open(File.join(file_settings[:location], to), 'a') { |f| f.write(mail) } + end + end end Base.class_eval do |