aboutsummaryrefslogblamecommitdiffstats
path: root/actionmailer/lib/action_mailer/delivery_method/file.rb
blob: 571e32df491168bcd0d6662c306c5be944087781 (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.destinations.uniq.each do |to|
          ::File.open(::File.join(settings[:location], to), 'a') { |f| f.write(mail) }
        end
      end
    end
  end
end