#coding=utf-8

import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr
import datetime

my_sender='gaoyazhe@igengmei.com'
my_pass = 'VCrKTui99a7ALhiK'
my_user='gaoyazhe@igengmei.com'
def mail():
    ret=True
    try:
        with open('/home/gmuser/esmm_data/submit.log') as f:
            stat_data = f.read()
            msg=MIMEText(stat_data,'plain','utf-8')
            msg['From']=formataddr(["高雅喆",my_sender])
            msg['To']=formataddr(["高雅喆",my_user])
            msg['Subject']= str(datetime.date.today())+"-esmm多目标模型训练指标统计"
            server=smtplib.SMTP_SSL("smtp.exmail.qq.com", 465)
            server.login(my_sender, my_pass)
            server.sendmail(my_sender,[my_user,],msg.as_string())
            server.quit()
    except Exception:
        ret=False
    return ret

ret=mail()
if ret:
    print("邮件发送成功")
else:
    print("邮件发送失败")