GMX&& Ruby Mail SMTP:“文件结束”

时间:2014-02-14 01:05:42

标签: ruby smtp pony

我无法通过smtp服务器连接Mail(或Pony来发送电子邮件,其中包含我知道正确的凭据,端口号和地址参数。但是,当使用邮件客户端(雷鸟,墨水......等)时,我能够很好地连接。

这是我得到的堆栈跟踪:

ruby gmx_test.rb
/Users/sy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/protocol.rb:153:in `read_nonblock': end of file reached (EOFError)
    from /Users/sy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/protocol.rb:153:in `rbuf_fill'
    from /Users/sy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/protocol.rb:134:in `readuntil'
    from /Users/sy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/protocol.rb:144:in `readline'
    from /Users/sy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/smtp.rb:937:in `recv_response'
    from /Users/sy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/smtp.rb:554:in `block in do_start'
    from /Users/sy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/smtp.rb:947:in `critical'
    from /Users/sy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/smtp.rb:554:in `do_start'
    from /Users/sy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/smtp.rb:519:in `start'
    from /Users/sy/.rvm/gems/ruby-2.1.0/gems/mail-2.5.4/lib/mail/network/delivery_methods/smtp.rb:112:in `deliver!'
    from /Users/sy/.rvm/gems/ruby-2.1.0/gems/mail-2.5.4/lib/mail/message.rb:2129:in `do_delivery'
    from /Users/sy/.rvm/gems/ruby-2.1.0/gems/mail-2.5.4/lib/mail/message.rb:234:in `deliver'
    from /Users/sy/.rvm/gems/ruby-2.1.0/gems/mail-2.5.4/lib/mail/mail.rb:140:in `deliver'
    from gmx_test.rb:29:in `<main>'

以下是代码生成:

require 'mail'

gmx_options = { :address              => "mail.gmx.com",
                :port                 => 465,
                :user_name            => '<username_redacted>@gmx.com',
                :password             => '<password_redacted>',
                :authentication       => 'plain',
                :enable_starttls_auto => true  }



Mail.defaults do
  delivery_method :smtp, gmx_options
end



Mail.deliver do
  to '<redacted>
  from '<username_redacted>@gmx.com'
  subject 'TEST'
  body 'Hi.'
end

以下是其中一个能够发送电子邮件的桌面电子邮件客户端的服务器设置的屏幕截图:

enter image description here

最终情节扭曲:如果我使用gmail的smtp,此代码有效。

感谢您有任何见解!

1 个答案:

答案 0 :(得分:1)

我在2017年遇到了这个问题,简单地将端口更改为587对我有用:

德国来源https://hilfe.gmx.net/pop-imap/pop3/serverdaten.html 基本上说端口465使用SSL加密,对于STARTTLS加密,你必须使用端口587。