require 'net/smtp' msg = [ "Subject: Test\n", "\n", "Now is the time\n" ] Net::SMTP.start( 'smtp.163.com', 25, "163.com", "[email protected]", "******", :login ) do |smtp| smtp.sendmail( msg, '[email protected]', '[email protected]' ) end
Net::SMTP.start(server, port, domain, acct, passwd, authtype)参数解释
server | 163 smtp服务器域名 |
port | 163 smtp服务器端口 |
domain | 163 email服务器域,就是@符号后面的字符串 |
acct | 163邮箱用户名 |
passwd | 163邮箱密码 |
authtype | 邮件发送验证方式,163是密码验证 |
smtp.sendmail(msg, from, to)参数解释
msg | message主题和内容 |
from | 从哪个邮件帐号发送 |
to | 发送到哪个邮件帐号,我这里发送到我的gmail邮箱 |