fix: Handle email sending failure with appropriate error response

pull/16162/head
wangruidong 2025-10-16 10:52:40 +08:00 committed by 老广
parent 4abf2bded6
commit a9b44103d4
2 changed files with 207 additions and 81 deletions

File diff suppressed because it is too large Load Diff

View File

@ -175,6 +175,8 @@ class SendMailView(View):
msg.attach_alternative(html_content, "text/html") msg.attach_alternative(html_content, "text/html")
filename = f"{title}-{timezone.now().strftime('%Y%m%d%H%M%S')}.pdf" filename = f"{title}-{timezone.now().strftime('%Y%m%d%H%M%S')}.pdf"
msg.attach(filename, pdf_bytes, "application/pdf") msg.attach(filename, pdf_bytes, "application/pdf")
try:
msg.send() msg.send()
except Exception as e:
return JsonResponse({"message": "邮件发送成功"}) return JsonResponse({"error": _('Failed to send email: ') + str(e)})
return JsonResponse({"message": _('Email sent successfully to ') + email})