您的位置:首页 > 编程语言 > Ruby

[Ruby] ruby 发送126邮箱邮件

2016-05-17 09:09 381 查看
弄了好久终于能用126邮箱发送邮件

(1) mail gem包地址

https://github.com/mikel/mail

(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: 添加附件

发送成功后:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: