import smtplib
from email.mime.text import MIMEText
from email.header import Header
from lightning_ape_api.settings import EMAIL_switch
class Notice:
def email(self,message,subject):
if EMAIL_switch ==1:
sender = '发件人邮箱'
receivers = ['****@qq.com']
message = MIMEText(message, 'plain', 'utf-8')
message['From'] = Header("发送者", 'utf-8')
message['To'] = Header("接收者", 'utf-8')
subject = subject
message['Subject'] = Header(subject, 'utf-8')
try:
password='这是密码,有些邮箱需要使用授权码'
smtp=smtplib.SMTP_SSL('smtp.exmail.qq.com')
smtp.connect('smtp.exmail.qq.com',465)
smtp.login(sender,password)
smtp.sendmail(sender, receivers, message.as_string())
print("邮件发送成功")
except smtplib.SMTPException:
print("Error: 无法发送邮件")
else:
print("邮件开关未开启")
if __name__=='__main__':
print(Notice().email(message='test',subject='test'))