模型训练完成之后自动发送训练结果
code展示
# -*- coding: utf-8 -*-
# @Time : 2022/4/22 下午5:50
# @Author : junzai
# @File : auto_send_emali.py
# @Software: PyCharm
# Import smtplib for the actual sending function
import smtplib
from email.mime.text import MIMEText
from email.header import Header
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
def send_email(subject="No subject", content="I am boring"):
mail_host = "smtp.163.com"
mail_user = "chinesejunzai@163.com"
mail_pw = "xxxx" # 授权码
sender = "chinesejunzai@163.com"
receiver = "chinesejunzai@163.com"
# Create the container (outer) email message.
msg = MIMEText(content, "plain", "utf-8")
msg['Subject'] = subject
msg['From'] = sender
msg['To'] = receiver
try:
smtp = smtplib.SMTP_SSL(mail_host, 994) # 实例化smtp服务器
smtp.login(mail_user, mail_pw) # 登录
smtp.sendmail(sender, receiver, msg.as_string())
print("Email send successfully")
except smtplib.SMTPException:
print("Error: email send failed")
if __name__ == '__main__':
send_email(subject="Training finished", content="I am boring")
163邮箱界面配置
程序中有个mail_pw是邮箱授权码,可以通过自己的邮箱获取。登录自己常有的邮箱,以163为例。打开设置,将SMPT服务开启
开启对应的选项
- 最后运行程序就可以在邮箱接收到对应的信息,这个可以在项目中, 模型训练之后, 添加到最后即可完成邮件的发送过程.