From f4f76772fb5c25357a54baaa9cd20f7e9a1cd653 Mon Sep 17 00:00:00 2001 From: Matthew Rudy Jacobs Date: Wed, 28 Oct 2009 09:17:59 +0000 Subject: abstract all of the ActionMailer delivery methods into their own classes. thereby the following are equivalent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../lib/action_mailer/delivery_method/sendmail.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 actionmailer/lib/action_mailer/delivery_method/sendmail.rb (limited to 'actionmailer/lib/action_mailer/delivery_method/sendmail.rb') diff --git a/actionmailer/lib/action_mailer/delivery_method/sendmail.rb b/actionmailer/lib/action_mailer/delivery_method/sendmail.rb new file mode 100644 index 0000000000..34e03b8060 --- /dev/null +++ b/actionmailer/lib/action_mailer/delivery_method/sendmail.rb @@ -0,0 +1,22 @@ +module ActionMailer + module DeliveryMethod + + # A delivery method implementation which sends via sendmail. + class Sendmail < Method + + self.settings = { + :location => '/usr/sbin/sendmail', + :arguments => '-i -t' + } + + def perform_delivery(mail) + sendmail_args = settings[:arguments] + sendmail_args += " -f \"#{mail['return-path']}\"" if mail['return-path'] + IO.popen("#{settings[:location]} #{sendmail_args}","w+") do |sm| + sm.print(mail.encoded.gsub(/\r/, '')) + sm.flush + end + end + end + end +end -- cgit v1.2.3