molokoV molokoV - 1 year ago 131
Ruby Question

`get_tagged_response' when using gem gmail

Im trying to use gmail gem with this code

require 'gmail'

gmail = Gmail.connect($username, $password)

gmail.inbox.find(:unread).each do |email|!

and returns this:

/home/ubuntu/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/imap.rb:1198:in `get_tagged_response': Unknown command c107mb38116751qgc (Net::IMAP::BadResponseError)
from /home/ubuntu/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/imap.rb:1250:in `block in send_command'
from /home/ubuntu/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
from /home/ubuntu/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/imap.rb:1232:in `send_command'
from /home/ubuntu/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/imap.rb:454:in `block in select'
from /home/ubuntu/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
from /home/ubuntu/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/imap.rb:452:in `select'
from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/gmail-0.6.0/lib/gmail/client/base.rb:207:in `switch_to_mailbox'
from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/gmail-0.6.0/lib/gmail/client/base.rb:164:in `block in mailbox'
from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/gmail-0.6.0/lib/gmail/client/base.rb:161:in `synchronize'
from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/gmail-0.6.0/lib/gmail/client/base.rb:161:in `mailbox'
from /home/ubuntu/.rvm/gems/ruby-2.3.0/gems/gmail-0.6.0/lib/gmail/client/base.rb:184:in `inbox'
from get-mail.rb:10:in `<main>'

Same code on other ubuntu instance works fine.
Im using gmail (0.6.0) and gmail_xoauth (0.4.2) and ubuntu 14.04.4

im a little bit lost with this one. maybe something related to locale setting.

any clue ?

Answer Source

@molokoV, I was able to reproduce the error that you are getting using a machine with OS X, so looks like Ubuntu is not the problem.

So, I searched the gem documentation and found this:

  • In Gmail Security Settings, enable access for less secure applications.

Note: if you have 2FA enabled, you can't enable this feature.

In alternative, Google provides a gem google-api-client, that also supports OAuth2. The full documentation and quick-start can be found in this link

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download