-
Notifications
You must be signed in to change notification settings - Fork 1
/
email_alerts.py
37 lines (27 loc) · 968 Bytes
/
email_alerts.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
import smtplib
from email.mime.text import MIMEText
import socket
class Email_alarm:
def __init__(self):
self.msg_from = '575548935@qq.com' # 发送方邮箱
self.passwd = 'dfdgxobhmvaebcba' # 填入发送方邮箱的授权码
self.msg_to = '575548935@qq.com' # 收件人邮箱
self.subject = socket.gethostname()
def send_mail(self, content):
msg = MIMEText(content)
msg['Subject'] = self.subject
msg['From'] = self.msg_from
msg['To'] = self.msg_to
try:
s = smtplib.SMTP_SSL("smtp.qq.com", 465)
s.login(self.msg_from, self.passwd)
s.sendmail(self.msg_from, self.msg_to, msg.as_string())
print("发送成功")
except:
print("发送失败")
finally:
s.quit()
if __name__ == "__main__":
email_alarm = Email_alarm()
email_alarm.send_mail("Hello!")
# print(socket.gethostname())