Sha256: 81a01ebf75a4f23a97a7fdcaaa4662daca17351e800476f37d6deb89b4a14f85

Contents?: true

Size: 1.75 KB

Versions: 96

Compression:

Stored size: 1.75 KB

Contents

module Mail
  # A delivery method implementation which sends via sendmail.
  # 
  # To use this, first find out where the sendmail binary is on your computer,
  # if you are on a mac or unix box, it is usually in /usr/sbin/sendmail, this will
  # be your sendmail location.
  # 
  #   Mail.defaults do
  #     delivery_method :sendmail
  #   end
  # 
  # Or if your sendmail binary is not at '/usr/sbin/sendmail'
  # 
  #   Mail.defaults do
  #     delivery_method :sendmail, :location => '/absolute/path/to/your/sendmail'
  #   end
  # 
  # Then just deliver the email as normal:
  # 
  #   Mail.deliver do
  #     to 'mikel@test.lindsaar.net'
  #     from 'ada@test.lindsaar.net'
  #     subject 'testing sendmail'
  #     body 'testing sendmail'
  #   end
  # 
  # Or by calling deliver on a Mail message
  # 
  #   mail = Mail.new do
  #     to 'mikel@test.lindsaar.net'
  #     from 'ada@test.lindsaar.net'
  #     subject 'testing sendmail'
  #     body 'testing sendmail'
  #   end
  # 
  #   mail.deliver!
  class Sendmail
    
    def initialize(values)
      self.settings = { :location       => '/usr/sbin/sendmail',
                        :arguments      => '-i -t' }.merge(values)
    end
    
    attr_accessor :settings

    def deliver!(mail)
      envelope_from = mail.return_path || mail.sender || mail.from_addrs.first
      return_path = "-f \"#{envelope_from}\"" if envelope_from

      arguments = [settings[:arguments], return_path].compact.join(" ")
      
      Sendmail.call(settings[:location], arguments, mail.destinations.join(" "), mail)
    end
    
    def Sendmail.call(path, arguments, destinations, mail)
      IO.popen("#{path} #{arguments} #{destinations}", "w+") do |io|
        io.puts mail.encoded.to_lf
        io.flush
      end
    end
  end
end

Version data entries

96 entries across 66 versions & 5 rubygems

Version Path
depengine-0.0.31 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/sendmail.rb
depengine-0.0.31 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/sendmail.rb
depengine-0.0.30 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/sendmail.rb
depengine-0.0.30 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/sendmail.rb
depengine-0.0.29 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/sendmail.rb
depengine-0.0.29 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/sendmail.rb
depengine-0.0.28 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/sendmail.rb
depengine-0.0.28 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/sendmail.rb
depengine-0.0.27 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/sendmail.rb
depengine-0.0.27 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/sendmail.rb
depengine-0.0.26 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/sendmail.rb
depengine-0.0.26 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/sendmail.rb
depengine-0.0.25 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/sendmail.rb
depengine-0.0.25 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/sendmail.rb
depengine-0.0.24 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/sendmail.rb
depengine-0.0.24 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/sendmail.rb
depengine-0.0.23 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/sendmail.rb
depengine-0.0.23 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/sendmail.rb
depengine-0.0.22 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/sendmail.rb
depengine-0.0.22 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/sendmail.rb