python代码训练完成后邮件通知功能
-
功能:邮件通知功能
说明:需要开通邮箱的stmp服务,使用时需要修改发件邮箱、收件邮箱、stmp服务授权密码
说明:
运行成功后python输出窗口打印“success”import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart import time def send_email(): time_info = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime()) message = MIMEMultipart() sender = 'xxxxxxx@126.com' # 参数1:发送者邮箱 receiver = 'xxxxxxx@qq.com' # 参数2:接受者邮箱 message['From'] = sender message['To'] = receiver password = 'xxxxxxxx' # 参数3:stmp服务授权密码 # 邮件的内容 content = "{0} 已完成:{0}".format(time_info) textApart = MIMEText(content) message.attach(textApart) # 邮件的文字部分 message['Subject'] = time_info # 邮件的标题 try: server = smtplib.SMTP('smtp.126.com') # 发件邮箱的SMTP服务器地址 server.login(sender, password) server.sendmail(sender, receiver, message.as_string()) print('success') server.quit() except smtplib.SMTPException as e: print('error:', e) # 打印错误
关于如何开启邮箱的SMTP服务
-
@180-8014 学到了,多谢
-
@158-8051
好文章,结合平台的官方文章“执行训练并自动上传结果后关机”,用起来更舒服。训练完自动关机停止计费,并保存数据,发邮件通知。妙的