imap = Net::IMAP.new('imap.gmail.com', 993, usessl = true, certs = nil, verify = false)
imap.authenticate('XOAUTH2', user.gmail, user.google_token)
当我在Heroku Scheduler函数上运行时,上面的代码给出了一个错误:
Unknown command: AUTHENTICATE
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/imap.rb:1158:in `get_tagged_response'
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/imap.rb:1210:in `block in send_command'
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/imap.rb:1192:in `send_command'
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/imap.rb:418:in `authenticate'
/app/app/models/user.rb:161:in `block in screen_email_for_probable_products'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/relation/delegation.rb:13:in `each'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/relation/delegation.rb:13:in `each'
/app/app/models/user.rb:155:in `screen_email_for_probable_products'
/app/lib/tasks/scheduler.rake:5:in `block in <top (required)>'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:236:in `call'
我以前测试过这个函数本地开发没有问题。有谁知道为什么?
答案 0 :(得分:1)
我发现问题是因为每次我想要与其他用户进行身份验证时都需要重新初始化。
imap = Net::IMAP.new('imap.gmail.com', 993, usessl = true, certs = nil, verify = false)