Newer
Older
py_east_money / SendEmail.py
bdapp on 14 Apr 2020 1 KB 加入邮件通知
# coding=utf-8

import smtplib
from email.mime.text import MIMEText
import traceback

class Email:
    
    @staticmethod
    def sendErr():
        # 第三方 SMTP 服务
        mail_host = "smtp.sina.com"  # 设置服务器
        mail_user = "ang101888@sina.com"  # 用户名
        mail_pass = "bc5bfc5377295e39"  # 口令
        sender = 'Warning<ang101888@sina.com>'
        receivers = ['belloving@qq.com']  # 接收邮件,可设置为你的QQ邮箱或者其他邮箱
        message = MIMEText(traceback.format_exc(), 'plain', 'utf-8')    # traceback.format_exc()为报错日志
        message['From'] = "{}".format(sender)
        message['To'] = ",".join(receivers)
        message['Subject'] = 'EastMoney-Project'

        try:
            smtpObj = smtplib.SMTP(mail_host, 25)   # 25 为 SMTP 端口号
            smtpObj.login(mail_user, mail_pass)
            smtpObj.sendmail(sender, receivers, message.as_string())
            print('邮件发送成功')
        except smtplib.SMTPException as e:
            print(e)

   


# notify = Email()
# notify.send('标题头', '请检查执行结果')