0

I have a simple python program as follows -

import imaplib mail = imaplib.IMAP4_SSL('mail.o365.mailserver.com') print mail.login('myuserid@domain.com', 'MyPassword') print('Logged in')

I receive an error - File "C:\Python27\lib\imaplib.py", line 520, in login raise self.error(dat[-1]) error: LOGIN failed.

I found a link - http://bioportal.weizmann.ac.il/course/python/PyMOTW/PyMOTW/docs/imaplib/index.html

However, this link stats that you get this error when the credentials are incorrect. EDIT - Please note that my credentials are correct.

Kindly note that the connection to my mailserver happens correctly and an instance is successfully received.

Can Anyone please comment on the issue.

Sree Nair
  • 91
  • 4
  • 11
  • Isn't there anyone who can throw some light on this problem ??? – Sree Nair Mar 09 '17 at 04:28
  • You don't have a lot of information to go on. I would look at things such as: 1. Double/Triple check hostname, port, username, password. 2. See if there are any security options to disable IMAP. Turn them off. 3. See if oauth or two-factor authentication are enabled for the account. – JosiahDaniels Mar 16 '17 at 14:11
  • See http://stackoverflow.com/questions/25413301/gmail-login-failure-using-python-and-imaplib – JosiahDaniels Mar 16 '17 at 14:13
  • I've run into the same issue. The problem isn't the credentials -- they are correct. I have a bot that logs in with the same credentials over and over again, and after running successfully for a few days it ran into this error. The credentials the bot was using nor the credentials to the account changed during this time. – Drew Jul 10 '17 at 13:12

1 Answers1

0

I had the same problem and I got in the Spam folder a Critical Security Alert email from Google. "Someone just used your password to try to sign in to your account. Google blocked them, but you should check what happened."

When you review the activity you can indicate that this was a secure attemp and grant access for it. That solved my issue