tags:

views:

2520

answers:

3

I just ran into an issue with Python's imaplib and Gmail's authentication mechanism:

>>> import imaplib
>>> imap = imaplib.IMAP4_SSL('imap.gmail.com', 993)
>>> imap.authenticate('[email protected]', 'Bob Dole likes your style!')
Traceback (most recent call last):
  ...
imaplib.error: AUTHENTICATE command error: BAD ['TODO (not supported yet) 31if3458825wff.5']

If authentication is unsupported, how does one log in?

A: 

I found the solution on this helpful blog post. Although Gmail doesn't support AUTHENTICATE, it does support the LOGIN capability, like so:

>>> imap.login('[email protected]', 'Bob Dole likes your style!')
('OK', ['[email protected] authenticated (Success)'])
cdleary
+2  A: 

The following works for me:

srv = imaplib.IMAP4_SSL("imap.gmail.com")
srv.login(account, password)

I think using login() is required.

Greg Hewgill
+5  A: 

Instead of

>>> imap.authenticate('[email protected]', 'Bob Dole likes your style!')

use

>>> imap.login('[email protected]', 'Bob Dole likes your style!')
Harley