【问题标题】:How to send a mail via ruby with mail gem?如何使用邮件宝石通过 ruby​​ 发送邮件?
【发布时间】:2020-06-14 16:43:07
【问题描述】:

我尝试使用 ruby​​ 邮件 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)*

有什么建议吗?

【问题讨论】:

  • 这有帮助吗? github.com/mikel/mail/issues/639我知道它是针对旧版本的 gem,但试一试。
  • 嘿另一个嗯,就是这样!非常非常感谢你!埃里克。

标签: ruby email smtp rubygems


【解决方案1】:

遵循本指南:

https://github.com/mikel/mail#usage

我认为你应该使用 A Mail.new 类在发送之前创建一个“新”邮件。

【讨论】:

    猜你喜欢
    • 2016-12-18
    • 2012-10-04
    • 2012-02-04
    • 1970-01-01
    • 2011-04-01
    • 2014-02-21
    • 2015-10-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多