class Mail::Sendmail
mail.deliver!
end
body ‘testing sendmail’
subject ‘testing sendmail’
from ‘ada@test.lindsaar.net’
to ‘mikel@test.lindsaar.net’
mail = Mail.new do
Or by calling deliver on a Mail message
end
body ‘testing sendmail’
subject ‘testing sendmail’
from ‘ada@test.lindsaar.net’
to ‘mikel@test.lindsaar.net’
Mail.deliver do
Then just deliver the email as normal:
end
delivery_method :sendmail, :location => ‘/absolute/path/to/your/sendmail’
Mail.defaults do
Or if your sendmail binary is not at ‘/usr/sbin/sendmail’
end
delivery_method :sendmail
Mail.defaults do
be your sendmail location.
if you are on a mac or unix box, it is usually in /usr/sbin/sendmail, this will
To use this, first find out where the sendmail binary is on your computer,
A delivery method implementation which sends via sendmail.
def self.call(path, arguments, destinations, encoded_message)
def self.call(path, arguments, destinations, encoded_message) popen "#{path} #{arguments} #{destinations}" do |io| io.puts ::Mail::Utilities.binary_unsafe_to_lf(encoded_message) io.flush end end
def self.popen(command, &block)
def self.popen(command, &block) IO.popen "#{command} 2>&1", 'w+', &block end
def self.popen(command, &block)
def self.popen(command, &block) IO.popen command, 'w+', :err => :out, &block end
def self.shellquote(address)
- Allows '+' to accept email addresses with them
- Wraps in double quotes
with the following modifications:
The following is an adaptation of ruby 1.9.2's shellwords.rb file,
def self.shellquote(address) # Process as a single byte sequence because not all shell # implementations are multibyte aware. # # A LF cannot be escaped with a backslash because a backslash + LF # combo is regarded as line continuation and simply ignored. Strip it. escaped = address.gsub(/([^A-Za-z0-9_\s\+\-.,:\/@~])/n, "\\\\\\1").gsub("\n", '') %("#{escaped}") end
def deliver!(mail)
def deliver!(mail) smtp_from, smtp_to, message = Mail::CheckDeliveryParams.check(mail) from = "-f #{self.class.shellquote(smtp_from)}" if smtp_from to = smtp_to.map { |_to| self.class.shellquote(_to) }.join(' ') arguments = "#{settings[:arguments]} #{from} --" self.class.call(settings[:location], arguments, to, message) end
def initialize(values)
def initialize(values) self.settings = self.class::DEFAULTS.merge(values) end