fix: add 10-second timeout to all SMTP connections

SMTP connections with no timeout were causing indefinite hangs when
connecting to invalid hosts. Also improved error display template.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-05 23:11:24 +01:00
parent bbcac245ab
commit 4c2f7f1121
2 changed files with 22 additions and 14 deletions

View File

@@ -149,11 +149,12 @@ class SMTPProvider(EmailProvider):
msg.attach(MIMEText(body_text, "plain", "utf-8"))
msg.attach(MIMEText(body_html, "html", "utf-8"))
# Connect and send
# Connect and send (10-second timeout to fail fast)
timeout = 10
if settings.smtp_use_ssl:
server = smtplib.SMTP_SSL(settings.smtp_host, settings.smtp_port)
server = smtplib.SMTP_SSL(settings.smtp_host, settings.smtp_port, timeout=timeout)
else:
server = smtplib.SMTP(settings.smtp_host, settings.smtp_port)
server = smtplib.SMTP(settings.smtp_host, settings.smtp_port, timeout=timeout)
try:
if settings.smtp_use_tls and not settings.smtp_use_ssl:
@@ -474,10 +475,12 @@ class ConfigurableSMTPProvider(EmailProvider):
msg.attach(MIMEText(body_text, "plain", "utf-8"))
msg.attach(MIMEText(body_html, "html", "utf-8"))
# Use 10-second timeout to fail fast on bad SMTP settings
timeout = 10
if self.config.get("smtp_use_ssl"):
server = smtplib.SMTP_SSL(self.config["smtp_host"], self.config["smtp_port"])
server = smtplib.SMTP_SSL(self.config["smtp_host"], self.config["smtp_port"], timeout=timeout)
else:
server = smtplib.SMTP(self.config["smtp_host"], self.config["smtp_port"])
server = smtplib.SMTP(self.config["smtp_host"], self.config["smtp_port"], timeout=timeout)
try:
if self.config.get("smtp_use_tls") and not self.config.get("smtp_use_ssl"):
@@ -718,11 +721,12 @@ class VendorSMTPProvider(EmailProvider):
msg.attach(MIMEText(body_text, "plain", "utf-8"))
msg.attach(MIMEText(body_html, "html", "utf-8"))
# Use vendor's SMTP settings
# Use vendor's SMTP settings (10-second timeout to fail fast)
timeout = 10
if self.settings.smtp_use_ssl:
server = smtplib.SMTP_SSL(self.settings.smtp_host, self.settings.smtp_port)
server = smtplib.SMTP_SSL(self.settings.smtp_host, self.settings.smtp_port, timeout=timeout)
else:
server = smtplib.SMTP(self.settings.smtp_host, self.settings.smtp_port)
server = smtplib.SMTP(self.settings.smtp_host, self.settings.smtp_port, timeout=timeout)
try:
if self.settings.smtp_use_tls and not self.settings.smtp_use_ssl: