-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSendEmail.py
50 lines (41 loc) · 1.97 KB
/
SendEmail.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
# encoding:utf-8
import argparse
import smtplib
from email.header import Header
from email.mime.text import MIMEText
def send(args):
mail_host = "smtp.qq.com" # 设置服务器
mail_user = "[email protected]" # 用户名
mail_pass = "vwmghvuwtvhbdabg" # 授权码,注意不是邮箱登录密码,是上述设置的授权密码!!!
sender = '[email protected]'
receivers = ['[email protected]'] # 接收邮件,可设置为你的QQ邮箱或者其他邮箱
content = ''
for arg in vars(args):
if not arg == 'title':
content = content + arg + ':' + str(getattr(args, arg)) + '\n\n'
message = MIMEText(str(content), 'plain', 'utf-8')
message['From'] = "张浩堃"
message['To'] = "我的邮箱"
subject = args.title
message['Subject'] = Header(subject, 'utf-8')
smtpObj = smtplib.SMTP()
smtpObj.connect(mail_host, 25)
smtpObj.set_debuglevel(1)
smtpObj.login(mail_user, mail_pass)
smtpObj.sendmail(sender, receivers, message.as_string())
print("================邮件发送成功================")
if __name__ == "__main__":
# Adding necessary input arguments
parser = argparse.ArgumentParser(description='args from command line')
parser.add_argument('--title', default="消息通知", type=str, help='title of email')
parser.add_argument('--type', default="success", type=str, help='type of training')
parser.add_argument('--acc_train', default="100%", type=str, help='acc of the train')
parser.add_argument('--acc_dev', default="100%", type=str, help='acc of the dev')
parser.add_argument('--acc_test', default="100%", type=str, help='acc of the test')
args = parser.parse_args()
send(args)
# 训练代码中的函数
# def SendEmail(args):
# # 执行命令发送邮件
# os.system(f'python SendEmail.py --title={args.title} --type={args.type} --acc_train={args.acc_train} '
# f'--acc_dev={args.acc_dev} --acc_test={args.acc_test}')