Obviously you need to use the correct settings for the specific email account


How to set up a multifunction device or application to send emails using Microsoft 365 or Office 365 | Microsoft Learn

I don't use smtp.office365.com but according to this article, port 587 should work if other settings are correct (server address / use SSL / password).
Otherwise, try port 995 or 993