用ruby来获取页面内容的代码很简单,查了下资料,试着写了个发送邮件的代码,看来用ruby来实现”java调用jruby获取网页内容(JDK1.5)"一文的需求会更方便,代码如下:
require 'net/http'
require 'uri'
require "net/smtp"
str =Net::HTTP.get(URI.parse('http://www.google.cn'));
#puts str
def sendemail(subject,content,to=nil)
from = "Youremail@163.com"
to = ["xxx@qq.com","xxx2@qq.com"] if to.nil?
sendmessage = "Subject: "+subject +"/n/n"+content
#参数含义为:'your.smtp.server', 25, 'mail.from.domain','Your Account', 'Your Password', AuthType
smtp = Net::SMTP.start('smtp.163.com',25,'163.com',Youremail@163.com','xxxxx',:login)
smtp.send_message sendmessage,from,to
smtp.finish
end
sendemail("测试",str,nil)
puts("--send ok ----");
SMTP支持的鉴权参数 AuthType的取值有3种:
1):plain
2):login
3):cram_md5
是不是很简洁^-^