【发布时间】:2015-09-27 05:11:29
【问题描述】:
当我尝试打开与我的 Office 365 服务的连接时,它失败了:
2.2.0 :001 > require 'net/imap'
=> true
2.2.0 :002 > port = '993'
=> "993"
2.2.0 :003 > imap = Net::IMAP.new('outlook.office365.com', port)
Net::IMAP::Error: connection closed
from /Users/cameronaziz/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/net/imap.rb:1077:in `initialize'
from (irb):3:in `new'
from (irb):3
我还需要设置什么?
这是我控制器中的代码:
require 'net/imap'
port = '993'
imap = Net::IMAP.new('outlook.office365.com', port)
imap.authenticate('LOGIN', '***@***.com', '***')
imap.examine('INBOX')
在我实际设置用户名/密码之前,new 命令(与控制台相同)失败。
~~~~~~~
设置:ssl => true 有效。但是现在我仍然无法连接,因为我得到了:
控制器:
imap = Net::IMAP.new('outlook.office365.com', {:port => '993', :ssl => true } )
imap.authenticate('LOGIN', '***@***.com', '***')
查看错误:
Net::IMAP::BadResponseError in EmailsController#connect
Command Argument Error. 11
视图中突出显示的行现在位于 authenticate 方法行上。
当我运行imap.capability:
["IMAP4", "IMAP4REV1", "AUTH=PLAIN", "AUTH=XOAUTH2", "SASL-IR", "UIDPLUS", "ID", "UNSELECT", "CHILDREN", "IDLE", "NAMESPACE", "LITERAL+"]
【问题讨论】:
-
基于
imap.capability,您需要使用其中一种方法进行身份验证。LOGIN不够用,因为您的 IMAP 服务器不支持它。Net::IMAP似乎支持PLAIN,但是:ruby-doc.org/stdlib-2.0.0/libdoc/net/imap/rdoc/Net/IMAP/…
标签: ruby-on-rails ruby imap