2008-03-12
记录一下支持ssl的发邮件
require "openssl"
require "net/smtp"
Net::SMTP.class_eval do
private
def do_start(helodomain, user, secret, authtype)
raise IOError, 'SMTP session already started' if @started
check_auth_args user, secret, authtype if user or secret
sock = timeout(@open_timeout) { TCPSocket.open(@address, @port) }
@socket = Net::InternetMessageIO.new(sock)
@socket.read_timeout = 60 #@read_timeout
check_response(critical { recv_response() })
do_helo(helodomain)
if starttls
raise 'openssl library not installed' unless defined?(OpenSSL)
ssl = OpenSSL::SSL::SSLSocket.new(sock)
ssl.sync_close = true
ssl.connect
@socket = Net::InternetMessageIO.new(ssl)
@socket.read_timeout = 60 #@read_timeout
do_helo(helodomain)
end
authenticate user, secret, authtype if user
@started = true
ensure
unless @started
# authentication failed, cancel connection.
@socket.close if not @started and @socket and not @socket.closed?
@socket = nil
end
end
def do_helo(helodomain)
begin
if @esmtp
ehlo helodomain
else
helo helodomain
end
rescue Net::ProtocolError
if @esmtp
@esmtp = false
@error_occured = false
retry
end
raise
end
end
def starttls
getok('STARTTLS') rescue return false
return true
end
def quit
begin
getok('QUIT')
rescue EOFError
end
end
end
发表评论
- 浏览: 69982 次
- 性别:

- 来自: 杭州

- 详细资料
搜索本博客
我的相册
dog
共 3 张
共 3 张
最近加入圈子
链接
最新评论
-
用回了netbeans,那个爽啊
IDEA 很怪 严重不适应 据说适应之后会iu相当的happy 现在eclips ...
-- by quiii -
编译lighttpd 1.5
apt-get install libglib2.0-dev libaio-d ...
-- by magicgod -
安装kvm,后现代的虚拟机
这个需要cpu支持的,我的intel core 2 Duo T5500就不支持了 ...
-- by beming -
spark汉化其实还需要改很 ...
怎么没有说怎么改啊。
-- by hf_rabbit -
常见的几种校验方式
不错,收藏了,正好要用二次密码校验,谢谢了
-- by jmajia






评论排行榜