from_name = 'localhost'
from_mail = '12345678@qq.com'
to_name = 'ks'
to_mail = '88888888@qq.com'
#Servers and Authentication
#smtp_host = 'smtp.qq.com'
smtp_host = 'smtp.163.com'
smtp_port = 25 #465 587 25
#smtp_domain = 'qq.com'
smtp_domain = 'localhost.localdomain'
smtp_user = "wangyi@163.com"
smtp_pwd = "xxxxxxxx"
#smtp_user = "12345678@qq.com"
#smtp_pwd = 'xxxxxxxx'
#The subject and the message
t = Time.now
subj = '1331 thinkpad test hopy'
msg_body = "send msg from ruby.n"
#The date/time should look something like: Thu, 03 Jan 2006 12:33:22 -0700
msg_date = t.strftime("%a, %d %b %Y %H:%M:%S +0800")
#Compose the message for the email
神马情况?考虑到tk对ruby的问题(见我另一篇在mac OS X下ruby使用tk的博文),我怀疑该ruby版本本身不支持原生openssl,这个版本是我在ruby-lang下载的ruby-2.1.5源代码编译并且安装的!遂用rvm下载了其ruby-2.1.5版本,一试竟然可以鸟!但随后发现hotmail.com的加密连接还是连不上,又换回QQ邮箱,用非加密的smtp,25端口连接。这回基本可以稳定发送了,如果换位163的邮箱测试发现更加稳定,上未重构的代码:
#!/usr/bin/ruby
#encoding:utf-8
require 'net/smtp'
require './smtp-tls.rb'
require 'mailfactory'
#Senders and Recipients
from_name = 'localhost'
from_mail = '12345678@qq.com'
to_name = 'ks'
to_mail = '88888888@qq.com'
#Servers and Authentication
#smtp_host = 'smtp.qq.com'
smtp_host = 'smtp.163.com'
smtp_port = 25 #465 587 25
#smtp_domain = 'qq.com'
smtp_domain = 'localhost.localdomain'
smtp_user = "wangyi@163.com"
smtp_pwd = "xxxxxxxx"
#smtp_user = "12345678@qq.com"
#smtp_pwd = 'xxxxxxxx'
#The subject and the message
t = Time.now
subj = '1331 thinkpad test hopy'
msg_body = "send msg from ruby.n"
#The date/time should look something like: Thu, 03 Jan 2006 12:33:22 -0700
msg_date = t.strftime("%a, %d %b %Y %H:%M:%S +0800")
#Compose the message for the email
#如果使用mailfactory发送则实际用不着msg格式了
msg = <<END_OF_MESSAGE
Date: #{msg_date}
From: #{from_name} <#{from_mail}>
To: #{to_name} <#{to_mail}>
Subject: #{subj}
#{msg_body}
END_OF_MESSAGE
mail = MailFactory.new
mail.to = to_mail
mail.from = from_mail
mail.subject = subj
mail.text = msg_body
mail.attach(File.expand_path("./mail.rb")) #发送附件
#smtp = Net::SMTP.new(smtp_host,587)
#smtp.enable_starttls
#Net::SMTP.start(smtp_host, smtp_port, smtp_domain, smtp_user, smtp_pwd, :plain) do |smtp|










