# ##发送邮件
#
# #coding=utf-8
#
# import smtplib
# from email.mime.text import MIMEText
# from email.utils import formataddr
# from email.mime.application import MIMEApplication
# import datetime
#
# from email.mime.multipart import MIMEMultipart
#
# my_sender='wangzhiwei@igengmei.com'
# my_pass = 'RiKEcsHAgesCZ7yd'
# my_user1='wangzhiwei@igengmei.com'
# my_user2='gaoyazhe@igengmei.com'
# my_user3='huangkai@igengmei.com'
# def mail():
#     ret = True
#     pdfFile = 'hypothesis.txt'
#     pdfApart = MIMEApplication(open(pdfFile, 'rb').read())
#     pdfApart.add_header('Content-Disposition', 'attachment', filename=pdfFile)
#     m = MIMEMultipart()
#     m.attach(pdfApart)
#     m['Subject'] = '数据指标监控数据（假设检验）'
#     m['From'] = '王志伟<wangzhiwei@igengmei.com>'
#
#
#     try:
#         # text = "Hi!\nHow are you?\nHere is the link you wanted:\nhttp://www.baidu.com"
#         # msg = MIMEText(text, 'plain', 'utf-8')
#         # msg['From'] = formataddr(["王志伟", my_sender])
#         # msg['To'] = my_user1
#         # 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_user1,my_user2,my_user3], m.as_string())
#         server.quit()
#     except Exception:
#         ret=False
#     return ret
#
# ret=mail()
# if ret:
#     print("邮件发送成功")
# else:
#     print("邮件发送失败")

#####尝试发送邮箱，不带附件

#coding=utf-8

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

my_sender='wangzhiwei@igengmei.com'
my_pass = 'RiKEcsHAgesCZ7yd'
my_user1='wangzhiwei@igengmei.com'
my_user2='zhangyanzhao@igengmei.com'
my_user3='zhaochen@igengmei.com'
my_user4='huangkai@igengmei.com'
my_user5='lixiaofang@igengmei.com'
my_user6='duanyingrong@igengmei.com'
my_user7='liuxiao@igengmei.com'
my_user8='gaoyazhe@igengmei.com'
def mail():
    ret=True
    try:
        with open('hypothesis.txt') as f:
            stat_data = f.read()
            msg=MIMEText(stat_data,'plain','utf-8')
            msg['From']=formataddr(["王志伟",my_sender])
            msg['To']=my_user1
            msg['Subject']= str(datetime.date.today())+"-数据指标监控数据（假设检验）"
            server=smtplib.SMTP_SSL("smtp.exmail.qq.com", 465)
            server.login(my_sender, my_pass)
            server.sendmail(my_sender,[my_user1,my_user2,my_user3,my_user4,my_user5,my_user6,my_user7,my_user8],msg.as_string())
            server.quit()
    except Exception:
        ret=False
    return ret

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