add mail system

This commit is contained in:
RainSun 2020-01-21 21:13:07 +08:00
parent 94cf469fae
commit a16952b1ce
2 changed files with 36 additions and 0 deletions

View File

@ -1,4 +1,6 @@
# coding=utf-8
from crawler import connection, getGrade, getSchedule
from mail import sendMail
import json
from hashlib import md5
from urllib.parse import urlencode, unquote_plus
@ -17,6 +19,8 @@ def manageLogin(request):
if res['errcode'] == 200:
# 登录成功并进行查询
grade = getGrade(res['ip'], res['s'])
if grade['errcode'] == 200:
sendMail('起来板砖啦!', '教务系统成绩信息已恢复查询,请查看', ['1144131090@qq.com','nayiyewosile@qq.com'])
schedule = getSchedule(res['ip'], res['s'])
return {'errcode': '200', 'errmsg': 'ok', 'student_name':res['student_name'], 'student_id':res['student_id'], 'grade': grade, 'schedule': schedule}
else:

32
lib/mail.py Normal file
View File

@ -0,0 +1,32 @@
# coding=utf-8
import smtplib
from email.mime.text import MIMEText
# 发送纯文本格式的邮件
def sendMail(title, content, mailto_list):
msg = MIMEText(content, 'plain', 'utf-8')
#发送邮箱地址
sender = '1144131090@qq.com'
#邮箱授权码,非登陆密码
password = 'gmzfcesmbgqhgfjb'
#收件箱地址
#receiver = '19xxxxxxx9@qq.com'
# mailto_list = ['1144131090@qq.com','nayiyewosile@qq.com'] #群发邮箱地址
#smtp服务器
smtp_server = 'smtp.qq.com'
#发送邮箱地址
msg['From'] = sender
#收件箱地址
#msg['To'] = receiver
msg['To'] =';'.join(mailto_list) #发送多人邮件写法
#主题
msg['Subject'] = title
server = smtplib.SMTP(smtp_server,25) # SMTP协议默认端口是25
server.login(sender,password) #ogin()方法用来登录SMTP服务器
server.set_debuglevel(1) #打印出和SMTP服务器交互的所有信息。
server.sendmail(sender,mailto_list,msg.as_string()) #msg.as_string()把MIMEText对象变成str server.quit()
# 第一个参数为发送者,第二个参数为接收者,可以添加多个例如:['hello@163.com','xxx@qq.com',]# 第三个参数为发送的内容
server.quit()