python-email

def sendEmail():
# 第三方 SMTP 服务
mail_host = "smtp.126.com" # 设置服务器
mail_user = "developios2016" # 用户名
mail_pass = "xxxx" # 口令

sender = 'developios2016@126.com'
receivers = ['ascomtohom@126.com'] # 接收邮件,可设置为你的QQ邮箱或者其他邮箱

message = MIMEText('WANR: xxx service maybe not working...', 'plain', 'utf-8')
message['From'] = "developios2016@126.com"
message['To'] = "ascomtohom@126.com"

subject = '日志文件需要检查'
message['Subject'] = Header(subject, 'utf-8')

try:
smtpObj = smtplib.SMTP()
smtpObj.connect(mail_host, 25) # 25 为 SMTP 端口号
smtpObj.set_debuglevel(1)
smtpObj.login(mail_user, mail_pass)
smtpObj.sendmail(sender, receivers, message.as_string())
smtpObj.quit()
print("邮件发送成功")

except smtplib.SMTPException:
import traceback
traceback.print_exc()
errMsg = traceback.format_exc()

print("Error: 无法发送邮件: " + errMsg)