Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SMTP Authentication error while while sending mail from outlook using python language

Tags:

python

email

import smtplib


smtpObj = smtplib.SMTP('smtp.office365.com', 587)

smtpObj.ehlo()

smtpObj.starttls()

smtpObj.login('[email protected]', ' abcde')

smtpObj.sendmail('[email protected]', '[email protected]', 'Subject: So long.\nDear Alice, so long and thanks for all the fish. Sincerely, Bob')

{}

smtpObj.close()

The error I am getting

SMTPAuthenticationError: (535, b'5.7.3 Authentication unsuccessful [BM1PR01CA0150.INDPRD01.PROD.OUTLOOK.COM]').
like image 783
Nandu Avatar asked Jul 22 '26 04:07

Nandu


1 Answers

Most likely, the authenticated SMTP (SMTP AUTH protocol) is disabled in your Exchange Online organization.

SMTP AUTH can be enabled/disabled on the organization level, or per-mailbox. Because SMTP AUTH only uses basic authentication, Microsoft recommends to disable it on the organization level and enable it only for individual accounts that still require it.

If security defaults are enabled in the organization, then SMTP AUTH is disabled.

SMTP AUTH can be enabled in Microsoft 365 admin center or using Exchange Online Powershell.

To make it simple, to enable SMTP AUTH for a single account:

  1. Go to the Microsoft 365 admin center (https://admin.microsoft.com/) > Users > Active users.
  2. Select the user you are going to send emails from, and go to the Mail tab.
  3. In the Email apps section click Manage email apps.
  4. Enable Authenticated SMTP and click Save changes.

After that you should be able to authenticate using the respective account.

Important: You need admin rights in your Office 365 organization to do that. Otherwise, ask your O365 org admin for help.

Further details: https://learn.microsoft.com/exchange/clients-and-mobile-in-exchange-online/authenticated-client-smtp-submission

like image 56
wombatonfire Avatar answered Jul 24 '26 17:07

wombatonfire



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!