fix: unable to send email for py backend (#16888)

### Summary

As title

Can send email now
<img width="2313" height="1941" alt="image"
src="https://github.com/user-attachments/assets/c129b3c7-7e40-4bdd-8430-f3b402b9cab1"
/>
<img width="1256" height="2760" alt="f6ba88c56fe3945a6d28564fc4d4c54f"
src="https://github.com/user-attachments/assets/ae2dbe0c-e2d4-494f-8b86-03e959ef4808"
/>
This commit is contained in:
Haruko386
2026-07-14 14:59:06 +08:00
committed by GitHub
parent 9289a183a2
commit 7a20920b12
2 changed files with 13 additions and 5 deletions

View File

@@ -19,6 +19,7 @@ from abc import ABC
import json
import smtplib
import logging
import ssl
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header
@@ -116,11 +117,17 @@ class Email(ToolBase, ABC):
if self.check_if_canceled("Email processing"):
return
context = smtplib.ssl.create_default_context()
with smtplib.SMTP(self._param.smtp_server, self._param.smtp_port) as server:
server.ehlo()
server.starttls(context=context)
context = ssl.create_default_context()
if int(self._param.smtp_port) == 465:
server = smtplib.SMTP_SSL(self._param.smtp_server, self._param.smtp_port, timeout=10, context=context)
else:
server = smtplib.SMTP(self._param.smtp_server, self._param.smtp_port, timeout=10)
with server:
server.ehlo()
if int(self._param.smtp_port) != 465:
server.starttls(context=context)
server.ehlo()
# Login
smtp_username = self._param.smtp_username or self._param.email

View File

@@ -162,7 +162,8 @@ async def send_email_html(to_email: str, subject: str, template_key: str, **cont
smtp = aiosmtplib.SMTP(
hostname=settings.MAIL_SERVER,
port=settings.MAIL_PORT,
use_tls=True,
use_tls=settings.MAIL_USE_SSL,
start_tls=settings.MAIL_USE_TLS,
timeout=10,
)