Outlook IMAP login failed using python

Akila Kavinda 21 Reputation points
2022-12-15T09:04:03.833+00:00

I am trying to connect my outlook using python. I have turned on the 2-factor authentication and created a new app password. I am unable to login. Please help to resolve this issue.

host = 'outlook.office365.com'
username = '#account#'
password = '#app password#'

mail = imaplib.IMAP4_SSL(host, port=993)
mail.login(username, password)

Error Message ###

raise self.error(dat[-1])
imaplib.error: b'LOGIN failed.'

Please help to resolve this.

Exchange Online
Exchange Online
A cloud-based service included in Microsoft 365, delivering scalable messaging and collaboration features with simplified management and automatic updates.
Outlook | Windows | Classic Outlook for Windows | For business
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Answer accepted by question author
  1. Andy David - MVP 159.7K Reputation points MVP Volunteer Moderator
    2022-12-15T21:46:05.717+00:00

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.