Created
May 6, 2010 19:20
-
-
Save robhurring/392585 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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