70 lines
1.5 KiB
Ruby
Executable File
70 lines
1.5 KiB
Ruby
Executable File
#!/usr/bin/env ruby
|
|
|
|
# Make sure we can require vendored gems
|
|
$:.unshift(*Dir.glob(File.expand_path("../../vendor/gems/*/lib", __FILE__)))
|
|
|
|
require "optparse"
|
|
|
|
require "mail"
|
|
|
|
options = {:smtp_ip => "127.0.0.1", :smtp_port => 1025}
|
|
|
|
OptionParser.new do |parser|
|
|
parser.banner = <<-BANNER.gsub /^ +/, ""
|
|
Usage: catchmail [options] [recipient ...]
|
|
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
|
|
|
|
parser.on("-f FROM", "Set the sending address") do |from|
|
|
options[:from] = from
|
|
end
|
|
|
|
parser.on("-oi", "Ignored option -oi") do |ignored|
|
|
end
|
|
parser.on("-t", "Ignored option -t") do |ignored|
|
|
end
|
|
parser.on("-q", "Ignored option -q") do |ignored|
|
|
end
|
|
|
|
parser.on("-x", "--no-exit", "Can't exit from the application") do
|
|
options[:no_exit] = true
|
|
end
|
|
|
|
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
|
|
|
|
message = Mail.new($stdin.read)
|
|
|
|
message.return_path = options[:from] if options[:from]
|
|
|
|
ARGV.each do |recipient|
|
|
if message.to.nil?
|
|
message.to = recipient
|
|
else
|
|
message.to << recipient
|
|
end
|
|
end
|
|
|
|
message.deliver
|