Temporary Server Error while connecting to Office 365 using SMTPLib

Jarosław Nowaczyk 1 Reputation point
2021-07-19T12:52:47.297+00:00

Hi,

I'm trying to connect to Office365 using SMTPLib library in Python. The code snipped looks following:

import smtplib
mailserver = smtplib.SMTP('smtp.office365.com',587)
mailserver.ehlo()
mailserver.starttls()
mailserver.login('******@email.com', 'password')
#Adding a newline before the body text fixes the missing message body
mailserver.sendmail('******@email.com','******@email.com','\npython email')
mailserver.sendmail() 
mailserver.quit()

The execution halts on mailserver.login() part. I'm receiving an error

SMTPAuthenticationError: (451, b'4.7.0 Temporary server error. Please try again later. PRX4 [PR3P191CA0050.EURP191.PROD.OUTLOOK.COM]')

I have enabled MFA and generated an app password which i'm using here. The SMTP Auth option is also enabled on my account.

Can anyone guide me what I might be missing?

Thanks.

Outlook | Windows | Classic Outlook for Windows | For business
{count} votes

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.