fix: 修复邮件测试序列类及API

pull/6950/head
Michael Bai 3 years ago committed by 老广
parent 08cd91c426
commit 2c74727b65

@ -9,6 +9,7 @@ from django.utils.translation import ugettext_lazy as _
from common.permissions import IsSuperUser from common.permissions import IsSuperUser
from common.utils import get_logger from common.utils import get_logger
from .. import serializers from .. import serializers
from django.conf import settings
logger = get_logger(__file__) logger = get_logger(__file__)
@ -24,14 +25,15 @@ class MailTestingAPI(APIView):
serializer = self.serializer_class(data=request.data) serializer = self.serializer_class(data=request.data)
serializer.is_valid(raise_exception=True) serializer.is_valid(raise_exception=True)
email_host = serializer.validated_data['EMAIL_HOST'] # 测试邮件时,邮件服务器信息从配置中获取
email_port = serializer.validated_data['EMAIL_PORT'] email_host = settings.EMAIL_HOST
email_host_user = serializer.validated_data["EMAIL_HOST_USER"] email_port = settings.EMAIL_PORT
email_host_password = serializer.validated_data['EMAIL_HOST_PASSWORD'] email_host_user = settings.EMAIL_HOST_USER
email_from = serializer.validated_data["EMAIL_FROM"] email_host_password = settings.EMAIL_HOST_PASSWORD
email_recipient = serializer.validated_data["EMAIL_RECIPIENT"] email_from = serializer.validated_data.get('EMAIL_FROM')
email_use_ssl = serializer.validated_data['EMAIL_USE_SSL'] email_use_ssl = settings.EMAIL_USE_SSL
email_use_tls = serializer.validated_data['EMAIL_USE_TLS'] email_use_tls = settings.EMAIL_USE_TLS
email_recipient = serializer.validated_data.get('EMAIL_RECIPIENT')
# 设置 settings 的值,会导致动态配置在当前进程失效 # 设置 settings 的值,会导致动态配置在当前进程失效
# for k, v in serializer.validated_data.items(): # for k, v in serializer.validated_data.items():

@ -8,14 +8,8 @@ __all__ = ['MailTestSerializer', 'EmailSettingSerializer', 'EmailContentSettingS
class MailTestSerializer(serializers.Serializer): class MailTestSerializer(serializers.Serializer):
EMAIL_HOST = serializers.CharField(max_length=1024, required=True)
EMAIL_PORT = serializers.IntegerField(default=25, min_value=1, max_value=65535)
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_FROM = serializers.CharField(required=False, allow_blank=True)
EMAIL_RECIPIENT = 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)
class EmailSettingSerializer(serializers.Serializer): class EmailSettingSerializer(serializers.Serializer):

Loading…
Cancel
Save