2011-05-29 00:39:45 -04:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
begin
|
|
|
|
require 'mail'
|
|
|
|
rescue LoadError
|
|
|
|
require 'rubygems'
|
|
|
|
require 'mail'
|
|
|
|
end
|
|
|
|
|
|
|
|
require 'optparse'
|
|
|
|
|
|
|
|
options = {:smtp_ip => '127.0.0.1', :smtp_port => 1025}
|
|
|
|
|
|
|
|
OptionParser.new do |parser|
|
|
|
|
parser.banner = <<-BANNER.gsub /^ +/, ""
|
|
|
|
Usage: catchmail [options]
|
|
|
|
sendmail-like interface to forward mail to MailCatcher.
|
|
|
|
BANNER
|
|
|
|
|
|
|
|
parser.on('--ip IP') do |ip|
|
|
|
|
options[:smtp_ip] = ip
|
|
|
|
end
|
|
|
|
|
|
|
|
parser.on('--smtp-ip IP', 'Set the ip address of the smtp server') do |ip|
|
|
|
|
options[:smtp_ip] = ip
|
|
|
|
end
|
|
|
|
|
|
|
|
parser.on('--smtp-port PORT', Integer, 'Set the port of the smtp server') do |port|
|
|
|
|
options[:smtp_port] = port
|
|
|
|
end
|
|
|
|
|
2012-01-23 02:29:10 -05:00
|
|
|
parser.on('-f FROM', 'Set the sending address') do |from|
|
|
|
|
options[:from] = from
|
|
|
|
end
|
|
|
|
|
2011-05-29 00:39:45 -04:00
|
|
|
parser.on('-h', '--help', 'Display this help information') do
|
|
|
|
puts parser
|
|
|
|
exit!
|
|
|
|
end
|
|
|
|
end.parse!
|
|
|
|
|
|
|
|
Mail.defaults do
|
|
|
|
delivery_method :smtp,
|
|
|
|
:address => options[:smtp_ip],
|
|
|
|
:port => options[:smtp_port]
|
|
|
|
end
|
|
|
|
|
2012-01-23 02:29:10 -05:00
|
|
|
message = Mail.new ARGF.read
|
|
|
|
message.return_path = options[:from] if options[:from]
|
|
|
|
message.deliver
|