# 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 = "belldev2018@sina.com" # 用户名
mail_pass = "a1b1465326ddd10d" # 口令
sender = 'belldev2018@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 = smtplib.SMTP_SSL(mail_host, 465) # 25 为 SMTP 端口号
smtpObj.login(mail_user, mail_pass)
smtpObj.sendmail(sender, receivers, message.as_string())
print('邮件发送成功')
except smtplib.SMTPException as e:
print(e)
@staticmethod
def sendNofity(content):
# 第三方 SMTP 服务
mail_host = "smtp.sina.com" # 设置服务器
mail_user = "belldev2018@sina.com" # 用户名
mail_pass = "a1b1465326ddd10d" # 口令
sender = 'belldev2018@sina.com'
receivers = ['belloving@qq.com'] # 接收邮件,可设置为你的QQ邮箱或者其他邮箱
message = MIMEText(content, 'html', '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 = smtplib.SMTP_SSL(mail_host, 465) # 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.sendNofity('请检查执行结果')