Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
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
ops
jumpserver
Commits
69e5ab43
Commit
69e5ab43
authored
May 29, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Bugfix] 解决发送邮件重启的问题
parent
757a31a5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
16 deletions
+11
-16
api.py
apps/common/api.py
+6
-16
tasks.py
apps/common/tasks.py
+5
-0
No files found.
apps/common/api.py
View file @
69e5ab43
...
...
@@ -21,23 +21,13 @@ class MailTestingAPI(APIView):
serializer
=
self
.
serializer_class
(
data
=
request
.
data
)
if
serializer
.
is_valid
():
email_host_user
=
serializer
.
validated_data
[
"EMAIL_HOST_USER"
]
kwargs
=
{
"host"
:
serializer
.
validated_data
[
"EMAIL_HOST"
],
"port"
:
serializer
.
validated_data
[
"EMAIL_PORT"
],
"username"
:
serializer
.
validated_data
[
"EMAIL_HOST_USER"
],
"password"
:
serializer
.
validated_data
[
"EMAIL_HOST_PASSWORD"
],
"use_ssl"
:
serializer
.
validated_data
[
"EMAIL_USE_SSL"
],
"use_tls"
:
serializer
.
validated_data
[
"EMAIL_USE_TLS"
]
}
connection
=
get_connection
(
timeout
=
5
,
**
kwargs
)
for
k
,
v
in
serializer
.
validated_data
.
items
():
if
k
.
startswith
(
'EMAIL'
):
setattr
(
settings
,
k
,
v
)
try
:
connection
.
open
()
except
Exception
as
e
:
return
Response
({
"error"
:
str
(
e
)},
status
=
401
)
try
:
send_mail
(
"Test"
,
"Test smtp setting"
,
email_host_user
,
[
email_host_user
],
connection
=
connection
)
subject
=
"Test"
message
=
"Test smtp setting"
send_mail
(
subject
,
message
,
email_host_user
,
[
email_host_user
])
except
Exception
as
e
:
return
Response
({
"error"
:
str
(
e
)},
status
=
401
)
...
...
apps/common/tasks.py
View file @
69e5ab43
...
...
@@ -2,6 +2,7 @@ from django.core.mail import send_mail
from
django.conf
import
settings
from
celery
import
shared_task
from
.utils
import
get_logger
from
.models
import
Setting
logger
=
get_logger
(
__file__
)
...
...
@@ -21,6 +22,10 @@ def send_mail_async(*args, **kwargs):
Example:
send_mail_sync.delay(subject, message, recipient_list, fail_silently=False, html_message=None)
"""
configs
=
Setting
.
objects
.
filter
(
name__startswith
=
'EMAIL'
)
for
config
in
configs
:
setattr
(
settings
,
config
.
name
,
config
.
cleaned_value
)
if
len
(
args
)
==
3
:
args
=
list
(
args
)
args
[
0
]
=
settings
.
EMAIL_SUBJECT_PREFIX
+
args
[
0
]
...
...
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