Class: Sendmail

Inherits:
Object
  • Object
show all
Defined in:
lib/sendmail.rb

Overview

Provides sendmail functionality for the reckoner script.

Instance Method Summary collapse

Constructor Details

#initialize(path, options) ⇒ Sendmail

Creates the class with a path to the binary (if any is given) and options.



7
8
9
10
# File 'lib/sendmail.rb', line 7

def initialize(path,options)
  @path = path
  @options = options
end

Instance Method Details

#send(to, from, subject, message) ⇒ Object

Sends the email.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sendmail.rb', line 13

def send(to,from,subject,message)
  path = @path || 'sendmail'
  options = @options || '-i -t'

  cmd = %|#{path} #{options}|

  body = "To: #{to}\n"
  body << "From: #{from}\n"
  body << "Subject: #{subject}\n"
  body << "\n#{message}"

  io = IO.popen(cmd,'w')
  io.puts body 
  io.close
end