mjs / imapclient

An easy-to-use, Pythonic and complete IMAP client library
https://imapclient.readthedocs.io/
Other
514 stars 84 forks source link

Failure logging into Outlook #602

Open DenofTranquility opened 1 month ago

DenofTranquility commented 1 month ago

I've had the same code be working for years but randomly I can't now login to the server. My credentials are in a separate .env file, I then use python-decouple to import them and login. I've checked the details multiple times and they are all correct, I use App Passwords from outlook as it doesn't work otherwise.

I used the interactive console to login with the same details and that worked strangely.

I've enabled logging but it hasn't given me any information that I can use.

2024-08-07 17:37:36,759 - DEBUG: < b'PEAA1 NO LOGIN failed.'
2024-08-07 17:37:36,760 - DEBUG:    matched b'(?P<tag>PEAA\\d+) (?P<type>[A-Z]+) (?P<data>.*)' => (b'PEAA1', b'NO', b'LOGIN failed.')
2024-08-07 17:37:36,760 - DEBUG: NO response: b'LOGIN failed.'
2024-08-07 17:37:36,760 - DEBUG: > b'PEAA2 LOGOUT'
2024-08-07 17:37:36,777 - DEBUG: < b'* BYE Microsoft Exchange Server IMAP4 server signing off.'
2024-08-07 17:37:36,777 - DEBUG:    matched b'\\* (?P<type>[A-Z-]+)( (?P<data>.*))?' => (b'BYE', b' Microsoft Exchange Server IMAP4 server signing off.', b'Microsoft Exchange Server IMAP4 server signing off.')
2024-08-07 17:37:36,777 - DEBUG: untagged_responses[BYE] 0 += ["b'Microsoft Exchange Server IMAP4 server signing off.'"]
2024-08-07 17:37:36,778 - DEBUG: BYE response: b'Microsoft Exchange Server IMAP4 server signing off.'
2024-08-07 17:37:36,778 - DEBUG: Logged out, connection closed

From the .env file:

IMAP_SERVER_NAME=outlook.office365.com
IMAP_PORT=993
IMAP_ENCRYPTION_METHOD=TLS

From the main.py:

IMAP_server_name = config('IMAP_SERVER_NAME')
IMAP_port = config('IMAP_PORT')
IMAP_encryption_method = config('IMAP_ENCRYPTION_METHOD')

username = config('USERNAME')
password = config('PASSWORD')

    with IMAPClient(IMAP_server_name) as server:
        print(f'[+] Logging in as {username}')
        server.login(username, password)
        print(f'[+] Entering folder {folder}')

Any ideas of what else I could try or have Microsoft nuked the login procedure?

wiene commented 1 month ago

Maybe your observed behavior is related to this Microsoft announcement. To quote the "Basic Authentication interim experience" section of this announcement:

Until September 16th, users signing into Outlook.com through Basic Authentication may experience recurring password prompts in Outlook and other third-party email applications. This is a known issue.

There are similar reports by other people, see e. g. the "July 2024" entry on https://email.faircode.eu/status.

DenofTranquility commented 1 month ago

Ahh ok, thanks for providing that article it might explain the issue and also the issue I was having in regards to Thunderbird as well. I'll have a look through the IMAPClient docs and see if there is a way to authenticate using OAuth

DenofTranquility commented 2 days ago

In case anybody else has this issue, I'm massively struggling to get this to work. Microsoft have made it difficult to actually get into emails. There's heaps of documentation which is good but overwhelming, new granular permissions you can add to an app... After registering it and this was all to get an OAUTH2 token. I've had to sign up to two different products and even though I can get a token, I still can't access my emails. I may have to purchase a subscription to another Microsoft product although that is unclear, I'm awaiting a sales rep to call me back.

Just a little vent of frustration