perf: Improve error handling for email sending in tasks

This commit is contained in:
wangruidong 2025-07-28 09:59:43 +08:00
parent be24f28d9b
commit 27db120908

View File

@ -65,13 +65,13 @@ def send_mail_async(*args, **kwargs):
"send_mail_async called with subject=%r, recipients=%r", subject, recipient_list "send_mail_async called with subject=%r, recipients=%r", subject, recipient_list
) )
try:
users = User.objects.filter(email__in=recipient_list).all() users = User.objects.filter(email__in=recipient_list).all()
for user in users: for user in users:
try:
with activate_user_language(user): with activate_user_language(user):
send_mail(connection=get_email_connection(), *args, **kwargs) send_mail(connection=get_email_connection(), *args, **kwargs)
except Exception as e: except Exception as e:
logger.error("Sending mail error: {}".format(e)) logger.error(f"Sending mail to {user.email} error: {e}")
@shared_task( @shared_task(