close

How to send SMTP email for office365 with python using tls/ssl

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to send SMTP email for office365 with python using tls/ssl in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to send SMTP email for office365 with python using tls/ssl?

  1. How to send SMTP email for office365 with python using tls/ssl?

    I bet 535 5.7.3 Authentication unsuccessful is thrown because authenticated SMTP (SMTP AUTH protocol) is disabled in your Exchange Online organization.

  2. send SMTP email for office365 with python using tls/ssl

    I bet 535 5.7.3 Authentication unsuccessful is thrown because authenticated SMTP (SMTP AUTH protocol) is disabled in your Exchange Online organization.

Method 1

Well, you are almost there. The following code will do the trick:

import smtplib

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

Method 2

Most likely, the problem is not in your code, but in the Exchange Online configuration.

I bet 535 5.7.3 Authentication unsuccessful is thrown because authenticated SMTP (SMTP AUTH protocol) is disabled in your Exchange Online organization.

Here you can find my answer explaining how you can enable SMTP AUTH for the user you are sending emails from. You have to be an Office 365 org admin to do that, or you can ask your administrator for help.

After that mailserver.starttls() should work. Notice that you don’t need to specify a certificate in that call.

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read