File: sendmail.rb

package info (click to toggle)
quickml 0.8-2
  • links: PTS
  • area: main
  • in suites: sid
  • size: 492 kB
  • sloc: ruby: 1,822; sh: 272; makefile: 174
file content (37 lines) | stat: -rw-r--r-- 634 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require 'net/smtp'

if ARGV.length < 3
  puts "usage: cat message | ruby sendmail.rb <from> <to> <subject> [cc]"
  exit 1
end

from = ARGV.shift
to = ARGV.shift
subject = ARGV.shift
cc = (ARGV.shift or "")
lines = readlines

contents = []
if lines.length == 1
  body = lines.first
  contents = [
    "To: #{to}\n", 
    "From: #{from}\n",
    "Subject: #{subject}\n",
    "Cc: #{cc}\n",
    "\n",
    body]
else
  body = lines.join('')
  contents = [
    "To: #{to}\n", 
    "From: #{from}\n",
    "Subject: #{subject}\n",
    "Cc: #{cc}\n",
    body]
end

Net::SMTP.start("localhost") {|smtp|
  smtp.send_mail(contents, from, to)
}