question

JarosawNowaczyk-7046 avatar image
0 Votes"
JarosawNowaczyk-7046 asked JadeLiang-MSFT commented

Temporary Server Error while connecting to Office 365 using SMTPLib

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@email.com', 'password')
 #Adding a newline before the body text fixes the missing message body
 mailserver.sendmail('from@email.com','to@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.

office-outlook-itpro
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @JarosawNowaczyk-7046,

Welcome to our forum, please kindly understand here we mainly focus on general issues about Outlook desktop client, I noticed that you have issues about connecting to Office 365 with Python, which is not supported in our forum.

As a supplement, here are some offcial supported ways about connecting to office 365, for your reference:
Connect to Exchange Online PowerShell
V1 module - Connect to Exchange Online PowerShell using MFA
Basic auth - Connect to Exchange Online PowerShell


0 Votes 0 ·

0 Answers