Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
executable file
·
49 lines (43 loc) · 1.6 KB

File metadata and controls

executable file
·
49 lines (43 loc) · 1.6 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Author: xurongzhong#126.com wechat:pythontesting qq:37391319
# CreateDate: 2018-1-8
# datas.py
import os
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
import smtplib
def send_mail(recipients, sub, content, from_name='比对测试',server="smtp.126.com",
files=[]):
EMAIL_SEND_USER = os.environ.get('EMAIL_SEND_USER')
EMAIL_SEND_PASSPORT = os.environ.get('EMAIL_SEND_PASSPORT')
msg = MIMEMultipart()
msg.attach(MIMEText(content, 'plain'))
msg['Subject'] = sub
msg['From'] = "{}<{}>".format(from_name, EMAIL_SEND_USER)
msg['To'] = ", ".join(recipients)
try:
s = smtplib.SMTP()
s.connect(server)
s.login(EMAIL_SEND_USER, EMAIL_SEND_PASSPORT)
for f in files or []:
with open(f, "rb") as fil:
part = MIMEApplication(
fil.read(),
Name=os.path.basename(f)
)
# After the file is closed
part['Content-Disposition'] = 'attachment; filename="%s"' % os.path.basename(f)
msg.attach(part)
print("send email to {}".format(recipients))
s.sendmail(EMAIL_SEND_USER, recipients, msg.as_string())
s.close()
return True
except Exception as e:
print(str(e))
return False
if __name__ == '__main__':
if send_mail(['xurongzhong@sensetime.com'],"活体比对测试结果", "测试结果",
files=[r'output.xls']):
print("发送成功")
Morty Proxy This is a proxified and sanitized view of the page, visit original site.