-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe_Mail.py
166 lines (150 loc) · 8.39 KB
/
e_Mail.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import smtplib
import models
from email.mime.text import MIMEText
from email.utils import formataddr
from log import log
from config import *
frmt = "%Y-%m-%d %H:%M:%S"
def signupMail(zkzh, signup_info):
ret = True
admin_zkzh = get_admin_zkzh()
admin_addr = get_email_admin_addr()
from_addr_name = get_email_from_addr_name()
from_addr = get_email_from_addr()
host = get_email_host()
passwd = get_email_passwd()
try:
if zkzh != admin_zkzh:
to_addr = models.getname_email(zkzh)[1]
to_addr_name = models.getname_email(zkzh)[0]
logmsg = "给%s的邮箱%s发送注册成功信息" % (to_addr_name, to_addr)
log(admin_zkzh, logmsg)
elif zkzh == admin_zkzh:
to_addr = admin_addr
to_addr_name = "管理员"
logmsg = "给%s的邮箱%s发送注册成功信息" % (to_addr_name, to_addr)
log(admin_zkzh, logmsg)
msgtext = signup_info
msg = MIMEText(msgtext, 'html', 'utf-8')
msg['From'] = formataddr([from_addr_name, from_addr]) # 括号里的对应发件人邮箱昵称、发件人邮箱账号
msg['To'] = formataddr([to_addr_name, to_addr]) # 括号里的对应收件人邮箱昵称、收件人邮箱账号
msg['Subject'] = "注册成功" # 邮件的主题,也可以说是标题
server = smtplib.SMTP_SSL(host, 465) # 发件人邮箱中的SMTP服务器,端口是25
server.login(from_addr, passwd) # 括号中对应的是发件人邮箱账号、邮箱密码
server.sendmail(from_addr, [to_addr, ], msg.as_string()) # 括号中对应的是发件人邮箱账号、收件人邮箱账号、发送邮件
server.quit() # 关闭连接
except Exception: # 如果 try 中的语句没有执行,则会执行下面的 ret=False
ret = False
return ret
def ipLocationMail(msg):
ret = True
admin_zkzh = get_admin_zkzh()
admin_addr = get_email_admin_addr()
from_addr_name = get_email_from_addr_name()
from_addr = get_email_from_addr()
host = get_email_host()
passwd = get_email_passwd()
try:
msgtext = 'IP地址归属查询接口异常:\n%s' % (msg)
msg = MIMEText(msgtext, 'plain', 'utf-8')
msg['From'] = formataddr([from_addr_name, from_addr]) # 括号里的对应发件人邮箱昵称、发件人邮箱账号
msg['To'] = formataddr(["管理员", admin_addr]) # 括号里的对应收件人邮箱昵称、收件人邮箱账号
msg['Subject'] = "IP地址归属查询接口异常" # 邮件的主题,也可以说是标题
server = smtplib.SMTP_SSL(host, 465) # 发件人邮箱中的SMTP服务器,端口是25
server.login(from_addr, passwd) # 括号中对应的是发件人邮箱账号、邮箱密码
server.sendmail(from_addr, [admin_addr, ], msg.as_string()) # 括号中对应的是发件人邮箱账号、收件人邮箱账号、发送邮件
server.quit() # 关闭连接
except Exception: # 如果 try 中的语句没有执行,则会执行下面的 ret=False
ret = False
return ret
def rebackTimeMail(zkzh, rebackTime):
ret = True
admin_zkzh = get_admin_zkzh()
admin_addr = get_email_admin_addr()
from_addr_name = get_email_from_addr_name()
from_addr = get_email_from_addr()
host = get_email_host()
passwd = get_email_passwd()
try:
to_addr = admin_addr
to_addr_name = "管理员"
if zkzh != admin_zkzh:
msgtext = '在查询%s的成绩时检测到504,官方自考成绩查询入口已关闭,将在 %s 重试' % (zkzh, rebackTime.strftime(frmt))
elif zkzh == admin_zkzh:
msgtext = '检测到504,官方自考成绩查询入口已关闭,将在 %s 重试' % (rebackTime.strftime(frmt))
log(zkzh, msgtext)
msg = MIMEText(msgtext, 'plain', 'utf-8')
msg['From'] = formataddr([from_addr_name, from_addr]) # 括号里的对应发件人邮箱昵称、发件人邮箱账号
msg['To'] = formataddr([to_addr_name, to_addr]) # 括号里的对应收件人邮箱昵称、收件人邮箱账号
msg['Subject'] = "检测到504,官方自考成绩查询入口已关闭" # 邮件的主题,也可以说是标题
server = smtplib.SMTP_SSL(host, 465) # 发件人邮箱中的SMTP服务器,端口是25
server.login(from_addr, passwd) # 括号中对应的是发件人邮箱账号、邮箱密码
server.sendmail(from_addr, [to_addr, ], msg.as_string()) # 括号中对应的是发件人邮箱账号、收件人邮箱账号、发送邮件
server.quit() # 关闭连接
except Exception: # 如果 try 中的语句没有执行,则会执行下面的 ret=False
ret = False
return ret
def nextTimeMail(zkzh, nextTime, response):
ret = True
admin_zkzh = get_admin_zkzh()
admin_addr = get_email_admin_addr()
from_addr_name = get_email_from_addr_name()
from_addr = get_email_from_addr()
host = get_email_host()
passwd = get_email_passwd()
try:
to_addr = admin_addr
to_addr_name = "管理员"
if zkzh != admin_zkzh:
msgtext = '在查询%s的成绩时检测到 %s,官方自考成绩查询入口异常,将在 %s 重试' % (zkzh, str(response), nextTime.strftime(frmt))
elif zkzh == admin_zkzh:
msgtext = '检测到 %s,官方自考成绩查询入口异常,将在 %s 重试' % (str(response), nextTime.strftime(frmt))
msg = MIMEText(msgtext, 'plain', 'utf-8')
msg['Subject'] = "检测到 %s,官方自考成绩查询入口异常" % (str(response)) # 邮件的主题,也可以说是标题
log(zkzh, msgtext)
msg['From'] = formataddr([from_addr_name, from_addr]) # 括号里的对应发件人邮箱昵称、发件人邮箱账号
msg['To'] = formataddr([to_addr_name, to_addr]) # 括号里的对应收件人邮箱昵称、收件人邮箱账号
server = smtplib.SMTP_SSL(host, 465) # 发件人邮箱中的SMTP服务器,端口是25
server.login(from_addr, passwd) # 括号中对应的是发件人邮箱账号、邮箱密码
server.sendmail(from_addr, [to_addr, ], msg.as_string()) # 括号中对应的是发件人邮箱账号、收件人邮箱账号、发送邮件
server.quit() # 关闭连接
except Exception: # 如果 try 中的语句没有执行,则会执行下面的 ret=False
ret = False
return ret
def Mail(zkzh, code, msg, content):
admin_zkzh = get_admin_zkzh()
admin_addr = get_email_admin_addr()
from_addr_name = get_email_from_addr_name()
from_addr = get_email_from_addr()
host = get_email_host()
passwd = get_email_passwd()
if zkzh != admin_zkzh:
to_addr = models.getname_email(zkzh)[1]
to_addr_name = models.getname_email(zkzh)[0]
elif zkzh == admin_zkzh:
to_addr = admin_addr
to_addr_name = "管理员"
ret = True
try:
if msg == "似乎有新成绩了":
msgtext = '<html><p>返回码 %s<br>\n%s<br>详细内容:</p>\n%s\n</html>' % (str(code), msg, content)
msg = MIMEText(msgtext, 'html', 'utf-8')
else:
msgtext = '在查询%s的成绩时,返回码 %s\n%s详细内容:\n%s' % (zkzh, str(code), msg, content)
msg = MIMEText(msgtext, 'plain', 'utf-8')
to_addr = admin_addr
to_addr_name = "管理员"
log(zkzh, msgtext)
msg['From'] = formataddr(["endless小龙的自考成绩查询系统", from_addr]) # 括号里的对应发件人邮箱昵称、发件人邮箱账号
msg['To'] = formataddr([to_addr_name, to_addr]) # 括号里的对应收件人邮箱昵称、收件人邮箱账号
if msg == "似乎有新成绩了":
msg['Subject'] = "似乎有新成绩了!" % (str(code)) # 邮件的主题,也可以说是标题
else:
msg['Subject'] = "返回码 %s" % (str(code)) # 邮件的主题,也可以说是标题
server = smtplib.SMTP_SSL(host, 465) # 发件人邮箱中的SMTP服务器,端口是25
server.login(from_addr, passwd) # 括号中对应的是发件人邮箱账号、邮箱密码
server.sendmail(from_addr, [to_addr, ], msg.as_string()) # 括号中对应的是发件人邮箱账号、收件人邮箱账号、发送邮件
server.quit() # 关闭连接
except Exception: # 如果 try 中的语句没有执行,则会执行下面的 ret=False
ret = False
return ret