[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
代码:
user_name: 邮箱登录完整名 如 123@126.com
password 不是邮箱登录密码,而是邮箱第三方客户端登录授权码
form: 从那个邮箱发送
to: 发送到的邮箱位置
add_file: 添加附件
发送成功后:
(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: 添加附件
发送成功后:
相关文章推荐
- [Ruby笔记]4. ruby 读写文件 File open read write new
- [Ruby笔记]3. 语法检查ruby -cw xx.rb /代码运行 ruby xx.rb/变量约定 @ @@ $
- Ruby 元编程 第二版随笔(三)
- Windows搭建Ruby环境
- Ruby 元编程 第二版随笔(二)
- [Ruby笔记]2. ruby基础的基础: irb --simple-prompt / puts print p/ false nil
- Ruby简介
- [Ruby笔记]1. ruby ruby oh~ ruby 安装
- ruby 使用Struct场景
- ruby4种比较符号
- Ruby little details to notice
- programming ruby
- ueditor之ruby on rails 版
- 跟我一起学ruby (转)
- 跟我一起学ruby (转)
- ruby两套教程
- ruby两套教程
- ruby cookbook
- Ruby中gem包管理器的用法及用bundler来管理多版本的gem
- ruby计算时间差