aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/lib/action_mailer/delivery_method/file.rb
diff options
context:
space:
mode:
authorMatthew Rudy Jacobs <MatthewRudyJacobs@gmail.com>2009-10-28 09:17:59 +0000
committerYehuda Katz <wycats@gmail.com>2009-11-01 02:23:47 +0100
commitf4f76772fb5c25357a54baaa9cd20f7e9a1cd653 (patch)
treec3095ca798d006fa5750538d862cf5fcc35da6ba /actionmailer/lib/action_mailer/delivery_method/file.rb
parent3f560386125adabe441facf2514ad53425e4af4e (diff)
downloadrails-f4f76772fb5c25357a54baaa9cd20f7e9a1cd653.tar.gz
rails-f4f76772fb5c25357a54baaa9cd20f7e9a1cd653.tar.bz2
rails-f4f76772fb5c25357a54baaa9cd20f7e9a1cd653.zip
abstract all of the ActionMailer delivery methods into their own classes. thereby the following are equivalent
ActionMailer::Base.delivery_method = :smtp ActionMailer::Base.delivery_method = ActionMailer::DeliveryMethod::Smtp we could equally set our own custom object as long as it provides the instance method :perform_delivery(mail) eg. class MySmsDeliveryMethod def perform_delivery(mail) Sms.send(mail['to'], mail['body']) end end MySmsMailer.delivery_method = MySmsDeliveryMethod.new Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'actionmailer/lib/action_mailer/delivery_method/file.rb')
-rw-r--r--actionmailer/lib/action_mailer/delivery_method/file.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/actionmailer/lib/action_mailer/delivery_method/file.rb b/actionmailer/lib/action_mailer/delivery_method/file.rb
new file mode 100644
index 0000000000..8807a05221
--- /dev/null
+++ b/actionmailer/lib/action_mailer/delivery_method/file.rb
@@ -0,0 +1,21 @@
+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) ? "#{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