aboutsummaryrefslogblamecommitdiffstats
path: root/actionmailer/lib/action_mailer/delivery_method/file.rb
blob: 6c8cdf4450993b4589c48d747be2fc80449229ba (plain) (tree)
1
2
3
4
5
6
7
8
9
                
 




                                                                        
                       
                                                                                                   











                                                                                      
require 'tmpdir'

module ActionMailer
  module DeliveryMethod

    # A delivery method implementation which writes all mails to a file.
    class File < Method
      self.settings = {
        :location       => defined?(Rails.root) ? "#{Rails.root}/tmp/mails" : "#{Dir.tmpdir}/mails"
      }

      def perform_delivery(mail)
        FileUtils.mkdir_p settings[:location]

        (mail.to + mail.cc + mail.bcc).uniq.each do |to|
          ::File.open(::File.join(settings[:location], to), 'a') { |f| f.write(mail) }
        end
      end
    end
  end
end