class Mail::Sendmail

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!

Attributes

settings[RW]

Public Class Methods

call(path, arguments, destinations, mail) click to toggle source
# File lib/mail/network/delivery_methods/sendmail.rb, line 55
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
new(values) click to toggle source
# File lib/mail/network/delivery_methods/sendmail.rb, line 39
def initialize(values)
  self.settings = { :location       => '/usr/sbin/sendmail',
                    :arguments      => '-i -t' }.merge(values)
end

Public Instance Methods

deliver!(mail) click to toggle source
# File lib/mail/network/delivery_methods/sendmail.rb, line 46
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