弄了好久终于能用126邮箱发送邮件
(1) mail gem包地址
(2) 在运行的时候出现的一些错误问题解决
http://www.altn.cn/qa/ec/qa_ec_mta.htm
代码:
#!/usr/bin/ruby
require 'mail'
smtp = { :address => 'smtp.126.com', :port => 25, :domain => '126.com',
:user_name => '******', :password => '******',
:enable_starttls_auto => true, :openssl_verify_mode => 'none' }
Mail.defaults { delivery_method :smtp, smtp }
mail = Mail.new do
from '*******'
to '*******'
subject 'test mail'
body 'body:hello send mail way 2 :)'
add_file File.expand_path("send_email.rb")
end
mail.deliver!
user_name: 邮箱登录完整名 如 123@126.com
password 不是邮箱登录密码,而是邮箱第三方客户端登录授权码
form: 从那个邮箱发送
to: 发送到的邮箱位置
add_file: 添加附件
发送成功后: