Outlook Python script can't login into office.365 server

Viewed 316

I have recently run into an issue with Outlook. I have been tasked with creating a python script that reads in emails from the office 365 server, using the imap-tools python library. I successfully setup and deployed the script. It was working fine until last week. The error given is:

"imap_tools.errors.MailboxLoginError: Response status "OK" expected, but "NO" received. Data: [b'LOGIN failed.']"

The code used to login is as follows:

username = os.environ["EMAILACCOUNT"]
password = os.environ["EMAILPASSWORD"]
server = "imap-mail.outlook.com"

from imap_tools import MailBox
MailBox(server).login(username, password, initial_folder="INBOX/my_folder")

Neither the login credentials nor the code changed at all, so I don't think those are the reasons for the script to break. I created a test email account, which was not attached to our company organization in outlook, and it worked with no issue. This leads me to think that there may have been an update to outlooks security settings specifically surrounding an organization. I have spent hours googling the issue with no luck. No one else seems to be reporting this problem, which yet again makes me think the error stems from an organizational setting. I've double checked and no organization setting was changed.

Any and all suggestions or hints as to what may be causing this problem would be greatly appreciated.

Thanks.

1 Answers
Related