发送邮件

import smtplib


sender = "Tom"
to = "Sally"
subject = "Test smtplib"

headers = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % (sender, to,
subject)
msg = headers + "Hello. How are you?"

mailserver = smtplib.SMTP("smtp.gmail.com", 587)
mailserver.ehlo()
mailserver.starttls()
mailserver.ehlo()
mailserver.login("[email protected]", password)
mailserver.sendmail("[email protected]",
"[email protected]", msg)
mailserver.close()

你可能感兴趣的:(发送邮件)