#!/usr/bin/env python import email.mime.text import smtplib username = 'foo@example.com' password = '****************' hostname = 'outlook.office365.com' msg = email.mime.text.MIMEText('test') msg['Subject'] = 'test' msg['From'] = 'foo@example.com' msg['To'] = 'bar@example.com' server = smtplib.SMTP(hostname, 587) server.ehlo() server.starttls() server.ehlo() server.login(username, password) server.sendmail( 'foo@example.com', ['bar@example.com'], msg.as_string(), ) server.close()