Skip to content

Instantly share code, notes, and snippets.

@robhurring
Created May 6, 2010 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robhurring/392585 to your computer and use it in GitHub Desktop.
Save robhurring/392585 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/ruby
require 'rubygems'
require 'action_mailer'
require 'optparse'
require 'fcntl'
require 'pp'
ActionMailer::Base.delivery_method = :sendmail
OPTIONS = {
:to => ['friend@domain.com'],
:subject => 'Hello World!',
:from => 'you@domain.com',
:body => 'Hello World!'
}
class Mailman < ActionMailer::Base
def test(options)
recipients options[:to]
subject options[:subject]
from options[:from]
body options[:body]
end
end
if __FILE__ == $0
OptionParser.new do |o|
o.banner = "Usage: #{$0} [options]"
o.on('-t', '--to=user,user,user', Array, 'Comma separated email addresses.'){ |t| OPTIONS[:to] = t }
o.on('-f', '--from=FROM', 'From email address.') { |f| OPTIONS[:from] = f }
o.on('-s', '--subject=SUBJECT', 'Subject line.'){ |s| OPTIONS[:subject] = s }
o.on('-b', '--body=BODY', "Email body. Also accepts STDIN: \"cat|#{$0}\""){ |b| OPTIONS[:body] = b }
end.parse!(ARGV)
OPTIONS[:body] = STDIN.read if STDIN.fcntl(Fcntl::F_GETFL, 0) == 0
puts "\n\nOptions:\n"
pp OPTIONS
puts "\nSending E-Mail:\n"
puts "Sent!" if Mailman.deliver_test(OPTIONS)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment