1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
def (): mail_host = "smtp.126.com" mail_user = "developios2016" mail_pass = "xxxx"
sender = '[email protected]' receivers = ['[email protected]']
message = MIMEText('WANR: xxx service maybe not working...', 'plain', 'utf-8') message['From'] = "[email protected]" message['To'] = "[email protected]"
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)
|
近期评论