Reputation: 862
I am working on writing a simple script to read unread mail from gmail through a python script. I have the following script, but when I run the python script, I get the IMAP error marked below. Any assistance in this issue is appreciated.
I have IMAP enabled in my gmail settings. Is there any other configuration that I need to take care of, to get this working?
import imaplib
obj = imaplib.IMAP4_SSL('imap.gmail.com','993')
obj.login('username','password')
obj.select()
obj.search(None,'Unseen')
where, username
is my gmail username, and password
is the password for my gmail account.
Traceback (most recent call last):
File "test.py", line 3, in <module>
obj.login('[email protected]',password)
File "/usr/lib/python2.7/imaplib.py", line 519, in login
raise self.error(dat[-1])
imaplib.error: [ALERT] Please log in via your web browser:
https://support.google.com/mail/accounts/answer/78754 (Failure)
Upvotes: 1
Views: 3336
Reputation: 13528
visibleman's answer is correct. As an alternative though you may wish to switch your script to using the Gmail API instead of IMAP. Gmail API uses OAuth 2.0 for authentication which is much more secure. Gmail API is also a much easier protocol to work with than IMAP.
Upvotes: 2
Reputation: 3315
I had the same problem. I am not sure which step finally solved it but here is what I did:
It seems that after this, you can again disable 'less secure' and it still works.
Upvotes: 1