import smtplib
sender = 'zeliang.yao-external@dpdgroup.com'
receivers = ['to@todomain.com']
message = """From: From Person <from@fromdomain.com>
Subject: SMTP e-mail test
This is a test e-mail message.
"""
try:
smtpObj = smtplib.SMTP('localhost')
smtpObj.sendmail(sender, receivers, message)
print "Successfully sent email"
except SMTPException:
print "Error: unable to send email"
import smtplib
s = smtplib.SMTP('smtp.office365.com', '587')
s.starttls()
s.login('zeliang.yao-external@dpdgroup.com', 'password')
s.sendmail('zeliang.yao-external@dpdgroup.com', 'zeliang.yao-external@dpdgroup.com, '', 'hello world')
s.quit()