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 Microsoft email and calendaring hosted service.
6,171 questions
Outlook Windows Classic Outlook for Windows For business
Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

Accepted answer
  1. Andy David - MVP 157.4K 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 Answers by the question author, which helps users to know the answer solved the author's problem.