Unverified Commit aebb9818 authored by BaiJiangJie's avatar BaiJiangJie Committed by GitHub

Merge pull request #3311 from jumpserver/dev_email

[Update] 邮件设置添加测试邮件收件人配置项
parents 90ec6a29 c9ca81e8
......@@ -357,6 +357,7 @@ EMAIL_PORT = 25
EMAIL_HOST_USER = 'noreply@jumpserver.org'
EMAIL_HOST_PASSWORD = ''
EMAIL_FROM = ''
EMAIL_RECIPIENT = ''
EMAIL_USE_SSL = False
EMAIL_USE_TLS = False
EMAIL_SUBJECT_PREFIX = '[JMS] '
......
This diff is collapsed.
......@@ -30,6 +30,7 @@ class MailTestingAPI(APIView):
serializer = self.serializer_class(data=request.data)
if serializer.is_valid():
email_from = serializer.validated_data["EMAIL_FROM"]
email_recipient = serializer.validated_data["EMAIL_RECIPIENT"]
email_host_user = serializer.validated_data["EMAIL_HOST_USER"]
for k, v in serializer.validated_data.items():
if k.startswith('EMAIL'):
......@@ -38,11 +39,12 @@ class MailTestingAPI(APIView):
subject = "Test"
message = "Test smtp setting"
email_from = email_from or email_host_user
send_mail(subject, message, email_from, [email_from])
email_recipient = email_recipient or email_from
send_mail(subject, message, email_from, [email_recipient])
except Exception as e:
return Response({"error": str(e)}, status=401)
return Response({"msg": self.success_message.format(email_host_user)})
return Response({"msg": self.success_message.format(email_recipient)})
else:
return Response({"error": str(serializer.errors)}, status=401)
......
......@@ -89,6 +89,10 @@ class EmailSettingForm(BaseForm):
"Tips: Send mail account, default SMTP account as the send account"
)
)
EMAIL_RECIPIENT = forms.CharField(
max_length=128, label=_("Test recipient"), initial='', required=False,
help_text=_("Tips: Used only as a test mail recipient")
)
EMAIL_USE_SSL = forms.BooleanField(
label=_("Use SSL"), initial=False, required=False,
help_text=_("If SMTP port is 465, may be select")
......
......@@ -7,6 +7,7 @@ class MailTestSerializer(serializers.Serializer):
EMAIL_HOST_USER = serializers.CharField(max_length=1024)
EMAIL_HOST_PASSWORD = serializers.CharField(required=False, allow_blank=True)
EMAIL_FROM = serializers.CharField(required=False, allow_blank=True)
EMAIL_RECIPIENT = serializers.CharField(required=False, allow_blank=True)
EMAIL_USE_SSL = serializers.BooleanField(default=False)
EMAIL_USE_TLS = serializers.BooleanField(default=False)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment