Pyhton 3.
import smtplib
from email.message import EmailMessage
user='[email protected]'
password = 'XXXXXXXXXXX'
smtpsrv = "smtp.office365.com"
smtpserver = smtplib.SMTP(smtpsrv,587)
msg = EmailMessage()
msg['Subject'] = 'Email Testing with Python'
msg['From'] = '[email protected]'
msg['To'] = '[email protected]'
smtpserver.starttls()
smtpserver.login(user, password)
smtpserver.send_message (msg)
smtpserver.close()
Complete info: https://www.aventistech.com/2016/03/07/python-send-email-via-office-365-tls/