-
Notifications
You must be signed in to change notification settings - Fork 0
/
messageUtil.py
38 lines (28 loc) · 1.76 KB
/
messageUtil.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
import smtplib
from email.mime.text import MIMEText
class sendMail():
smtp_adress = 'smtp.qq.com'
def __init__(self, from_mail, from_passwd, send_list):
self.from_mail = from_mail
self.from_passwd = from_passwd
self.send_list = send_list
def send(self, send_title, send_content):
msg = MIMEText(send_content, _charset='utf-8')
msg['Subject'] = send_title
msg['From'] = self.from_mail
msg['To'] = ';'.join(self.send_list)
mailServer = smtplib.SMTP(self.smtp_adress, 25)
mailServer.login(self.from_mail, self.from_passwd)
mailServer.sendmail(self.from_mail, self.send_list, msg.as_string())
mailServer.quit()
def send_email(message, title='实验结果报告', from_mail='[email protected]', from_passwd='l13317053539jy', to_list=['[email protected]']):
sendMail(from_mail, from_passwd, to_list).send(title, message)
# if __name__ == '__main__':
# # send_list = ['[email protected]']
# send_email("1我是内容,第一行\n我是第二行\n我是第三行")
def job_start(message="job start!", title='超算job运行监控', from_mail='[email protected]', from_passwd='l13317053539jy', to_list=['[email protected]']):
send_email(from_mail, from_passwd, to_list).send(title, message)
def job_finish(message="job finish!", title='超算job运行监控', from_mail='[email protected]', from_passwd='l13317053539jy', to_list=['[email protected]']):
send_email(from_mail, from_passwd, to_list).send(title, message)
def job_failed(message="job failed!", title='超算job运行监控', from_mail='[email protected]', from_passwd='l13317053539jy', to_list=['[email protected]']):
send_email(from_mail, from_passwd, to_list).send(title, message)