Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
Test
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
曹燕
Test
Commits
ac4e868b
Commit
ac4e868b
authored
Nov 25, 2019
by
huangqiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改执行方式
parent
a99055b4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
0 deletions
+55
-0
run.conf
Interface_Atuo_test/jiyunying/run.conf
+3
-0
sendemail.py
Interface_Atuo_test/jiyunying/sendemail.py
+52
-0
No files found.
Interface_Atuo_test/jiyunying/run.conf
0 → 100644
View file @
ac4e868b
[
test
]
student_new
=
reception
/
testsuites
/
apply_stuent_new
.
yml
\ No newline at end of file
Interface_Atuo_test/jiyunying/sendemail.py
0 → 100644
View file @
ac4e868b
# coding=utf-8
import
smtplib
import
common
from
email.mime.text
import
MIMEText
from
email.utils
import
formataddr
from
email.mime.multipart
import
MIMEMultipart
class
SendEmail
:
def
__init__
(
self
):
self
.
__get_email_conf
()
self
.
smt_obj
=
smtplib
.
SMTP_SSL
(
self
.
host
,
self
.
port
)
def
__get_email_conf
(
self
):
self
.
host
=
common
.
readconf
(
"email"
,
"host"
)
self
.
port
=
common
.
readconf
(
"email"
,
"port"
)
self
.
from_adress
=
common
.
readconf
(
"email"
,
"from_adress"
)
self
.
password
=
common
.
readconf
(
"email"
,
"password"
)
self
.
to_adresses
=
common
.
readconf
(
"email"
,
"to_adresses"
)
.
split
(
","
)
def
send_email
(
self
,
subject
,
text
,
html_msg
=
None
,
attachments
=
None
):
message
=
MIMEMultipart
()
# 发件人邮箱账号
message
[
'From'
]
=
self
.
from_adress
# 收件人邮箱账号
message
[
'To'
]
=
";"
.
join
(
self
.
to_adresses
)
message
[
'Subject'
]
=
subject
message
.
attach
(
MIMEText
(
text
,
'plain'
,
'utf-8'
))
if
html_msg
:
message
.
attach
(
MIMEText
(
html_msg
,
'html'
,
'utf-8'
))
# 构造附件1,传送当前目录下的 test.txt 文件
if
isinstance
(
attachments
,
list
)
and
attachments
:
for
attachment
in
attachments
:
att
=
MIMEText
(
open
(
attachment
,
'rb'
)
.
read
(),
'base64'
,
'utf-8'
)
att
[
"Content-Type"
]
=
'application/octet-stream'
# 这里的filename可以任意写,写什么名字,邮件中显示什么名字
att
[
"Content-Disposition"
]
=
'attachment; filename="
%
s"'
%
attachment
message
.
attach
(
att
)
try
:
self
.
smt_obj
.
login
(
self
.
from_adress
,
self
.
password
)
self
.
smt_obj
.
sendmail
(
self
.
from_adress
,
self
.
to_adresses
,
message
.
as_string
())
print
(
"邮件发送成功"
)
self
.
smt_obj
.
quit
()
except
smtplib
.
SMTPException
as
e
:
print
(
"Error: 邮件发送失败"
,
e
)
self
.
smt_obj
.
quit
()
if
__name__
==
"__main__"
:
send_email
=
SendEmail
()
send_email
.
send_email
(
"测试邮件"
,
"测试内容"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment