Add catchmail, a sendmail-analogue for deliverying to MailCatcher via SMTP.

This commit is contained in:
Samuel Cochran 2011-05-29 12:39:45 +08:00
parent 53ca9485e1
commit 531a5c07f6
2 changed files with 45 additions and 1 deletions

44
bin/catchmail Executable file
View File

@ -0,0 +1,44 @@
#!/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
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
Mail.deliver ARGF.read

View File

@ -23,7 +23,7 @@ Gem::Specification.new do |s|
"views/**/*" "views/**/*"
] ]
s.require_paths = ["lib"] s.require_paths = ["lib"]
s.executables = ["mailcatcher"] s.executables = ["mailcatcher", "catchmail"]
s.extra_rdoc_files = ["README.md", "LICENSE"] s.extra_rdoc_files = ["README.md", "LICENSE"]
s.required_ruby_version = '>= 1.8.7' s.required_ruby_version = '>= 1.8.7'