ruby - 如何使用邮件宝石通过 ruby 发送邮件?
问题描述
我尝试使用 ruby mail gem 发送一封简单的邮件:
require 'mail'
options = { :address => "smtp.1und1.de",
:port => 465,
:domain => 'xyz.info',
:user_name => 'abc@xyz.info',
:password => 'yessss',
:authentication => 'login',
:enable_starttls_auto => true }
Mail.defaults do
delivery_method :smtp, options
end
Mail.deliver do
to 'info@xyz.de'
from 'info@xyz.de'
subject 'testing sendmail'
body 'testing sendmail'
end
但我得到的只是以下错误:
*H:\04_PRUPLA\12_RUBY_TOOLS\21_MAILER>ruby MAILER_001.rb
Traceback (most recent call last):
13: from MAILER_001.rb:17:in `<main>'
12: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/mail-2.7.1/lib/mail/mail.rb:133:in `deliver'
11: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/mail-2.7.1/lib/mail/message.rb:262:in `deliver'
10: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/mail-2.7.1/lib/mail/message.rb:2159:in `do_delivery'
9: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/mail-2.7.1/lib/mail/network/delivery_methods/smtp.rb:100:in `deliver!'
8: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/mail-2.7.1/lib/mail/network/delivery_methods/smtp.rb:109:in `start_smtp_session'
7: from C:/Ruby27-x64/lib/ruby/2.7.0/net/smtp.rb:518:in `start'
6: from C:/Ruby27-x64/lib/ruby/2.7.0/net/smtp.rb:553:in `do_start'
5: from C:/Ruby27-x64/lib/ruby/2.7.0/net/smtp.rb:954:in `critical'
4: from C:/Ruby27-x64/lib/ruby/2.7.0/net/smtp.rb:553:in `block in do_start'
3: from C:/Ruby27-x64/lib/ruby/2.7.0/net/smtp.rb:944:in `recv_response'
2: from C:/Ruby27-x64/lib/ruby/2.7.0/net/protocol.rb:201:in `readline'
1: from C:/Ruby27-x64/lib/ruby/2.7.0/net/protocol.rb:191:in `readuntil'
C:/Ruby27-x64/lib/ruby/2.7.0/net/protocol.rb:225:in `rbuf_fill': end of file reached (EOFError)*
有什么建议吗?
解决方案
推荐阅读
- java - 我的应用程序在模拟器(Pixel 2 Api 25)上运行,但不在 android 设备上运行(Andriod 版本 [9、8 等])
- docker - Nginx https 问题 docker-compose
- git - 新存储库的 Github 权限被拒绝
- xcode - IBOutlet 创建双重引用
- c++ - 内联 asm 编译器屏障(内存破坏器)算作外部函数还是静态函数调用?
- amazon-web-services - 带有发电机数据库的 yaml SAM 本地
- collision-detection - Phaser:如何检测 Phaser.Geom.Line 和 Phaser.Geom.Point 之间的碰撞?
- c++ - C++:返回一个本地对象,但效果不佳
- .net - 图像未显示在 vb.net 的 datagridview 列中
- r - data.table:如何将字符向量传递给函数 get data.table 以将其内容视为列名?