def sendEmail(): mail_host = "smtp.126.com" mail_user = "developios2016" mail_pass = "xxxx"
sender = 'developios2016@126.com' receivers = ['ascomtohom@126.com']
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) 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)
|