diff --git a/apps/auth1/email_code_view.py b/apps/auth1/email_code_view.py index 54cf9bf..4e15305 100644 --- a/apps/auth1/email_code_view.py +++ b/apps/auth1/email_code_view.py @@ -4,6 +4,7 @@ from rest_framework.exceptions import ParseError from apps.auth1.serializers import EmailCodeSerializer from django.core.cache import cache from apps.utils.tools import rannum +from server.settings import get_sysconfig class EmailCodeView(CreateAPIView): @@ -30,12 +31,22 @@ class EmailCodeView(CreateAPIView): # 缓存验证码,有效期5分钟 cache.set(cache_key, code, 60 * 5) - # 使用 send_mail_task 发送验证码邮件 - from apps.utils.tasks import send_mail_task - send_mail_task.delay( - subject='登录验证码', - message=f'您的验证码是:{code},5分钟内有效。如非本人操作,请忽略此邮件。', - recipient_list=[email] - ) + # 使用 MyThread 发送验证码邮件 + from django.core.mail import send_mail + from apps.utils.thread import MyThread + + def send_email(): + config = get_sysconfig() + base_name_short = config['base']['base_name_short'] + send_mail( + subject=f'{base_name_short}-验证码', + message=f'您的验证码是:{code},5分钟内有效。如非本人操作,请忽略此邮件。', + from_email=None, # 使用默认发件人 + recipient_list=[email], + fail_silently=False + ) + + thread = MyThread(target=send_email) + thread.start_p() - return Response({'message': '验证码已发送'}) + return Response({'ok_msg': '验证码已发送'})