Python-smtp connection to send Outlook mail

Akash J 20 Reputation points
2023-09-14T13:10:38.2233333+00:00

When running Python code to send an email using SMTP, I keep encountering the following error: SMTPAuthenticationError: (535, b'5.7.3 Authentication unsuccessful [PN0PR01CA0001.INDPRD01.PROD.OUTLOOK.COM 2023-09-14T13:02:12.713Z 08DBB46FC88CCB87]'. I have double-checked that the username and password are correct. What steps should I take to resolve this authentication issue?

Exchange Online
Exchange Online
A Microsoft email and calendaring hosted service.
6,171 questions
Outlook Windows Classic Outlook for Windows For business
0 comments No comments
{count} votes

Accepted answer
  1. Kael Yao 37,746 Reputation points Moderator
    2023-09-15T03:23:16.6766667+00:00

    Hi @Akash J,

    Are you using basic authentication in your code?

    If yes, by default SMTP basic authentication is supposed to be disabled in your tenant.

    To enable basic authentication, please make sure you have these settings set correctly:

    Error: Authentication unsuccessful

    Alternatively, if you can use Oauth instead in your code, you do not need to configure these settings to enable SMTP basic auth.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Akash J 20 Reputation points
    2023-09-20T07:13:34.03+00:00

    Hello @Kael Yao

    Thank you for the response, and it is clear. I raised this with my admin team, and I think it will now be sorted.

    0 comments No comments

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.