Class: Mail::FileDelivery
- Includes:
- CheckDeliveryParams
- Defined in:
- lib/mail/network/delivery_methods/file_delivery.rb
Overview
FileDelivery class delivers emails into multiple files based on the destination address. Each file is appended to if it already exists.
So if you have an email going to fred@test, bob@test, joe@anothertest, and you set your location path to /path/to/mails then FileDelivery will create the directory if it does not exist, and put one copy of the email in three files, called by their message id
Make sure the path you specify with :location is writable by the Ruby process running Mail.
Instance Attribute Summary collapse
-
#settings ⇒ Object
Returns the value of attribute settings.
Instance Method Summary collapse
- #deliver!(mail) ⇒ Object
-
#initialize(values) ⇒ FileDelivery
constructor
A new instance of FileDelivery.
Methods included from CheckDeliveryParams
Constructor Details
#initialize(values) ⇒ FileDelivery
Returns a new instance of FileDelivery.
24 25 26 |
# File 'lib/mail/network/delivery_methods/file_delivery.rb', line 24 def initialize(values) self.settings = { :location => './mails' }.merge!(values) end |
Instance Attribute Details
#settings ⇒ Object
Returns the value of attribute settings.
28 29 30 |
# File 'lib/mail/network/delivery_methods/file_delivery.rb', line 28 def settings @settings end |
Instance Method Details
#deliver!(mail) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mail/network/delivery_methods/file_delivery.rb', line 30 def deliver!(mail) check_params(mail) if ::File.respond_to?(:makedirs) ::File.makedirs settings[:location] else ::FileUtils.mkdir_p settings[:location] end mail.destinations.uniq.each do |to| ::File.open(::File.join(settings[:location], File.basename(to.to_s)), 'a') { |f| "#{f.write(mail.encoded)}\r\n\r\n" } end end |