Sha256: 0d284e581477d79a5a03ed191b396fb56970123d8202b8a972da52f0171d9d2f

Contents?: true

Size: 1.77 KB

Versions: 95

Compression:

Stored size: 1.77 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.escape_for_shell + '"' if envelope_from

      arguments = [settings[:arguments], return_path].compact.join(" ")

      self.class.call(settings[:location], arguments, mail.destinations.collect(&:escape_for_shell).join(" "), mail)
    end

    def self.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

95 entries across 87 versions & 11 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/sendmail.rb
classiccms-0.7.4 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/sendmail.rb
classiccms-0.7.3 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/sendmail.rb
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/network/delivery_methods/sendmail.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/mail-2.4.4/lib/mail/network/delivery_methods/sendmail.rb
classiccms-0.7.2 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/sendmail.rb
classiccms-0.7.1 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/sendmail.rb
active_mailer-0.0.9 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/network/delivery_methods/sendmail.rb
active_mailer-0.0.8 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/network/delivery_methods/sendmail.rb
active_mailer-0.0.7 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/network/delivery_methods/sendmail.rb
active_mailer-0.0.6 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/network/delivery_methods/sendmail.rb
classiccms-0.7.0 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/sendmail.rb
challah-1.0.0.beta vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/sendmail.rb
active_mailer-0.0.5 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/network/delivery_methods/sendmail.rb
active_mailer-0.0.4 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/network/delivery_methods/sendmail.rb
active_mailer-0.0.3 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/network/delivery_methods/sendmail.rb
challah-0.9.1.beta.3 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/sendmail.rb
devise_sociable-0.1.0 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/sendmail.rb
challah-0.9.1.beta vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/sendmail.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/network/delivery_methods/sendmail.rb