From fb3edfa7a271e06fc357d29ef91539f40750e3b1 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 9 Mar 2026 12:52:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96email=20code=20?= =?UTF-8?q?=E5=8F=91=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/auth1/email_code_view.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) 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': '验证码已发送'})