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_text, "plain", "utf-8"))
msg.attach(MIMEText(body_html, "html", "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: 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: else:
server = smtplib.SMTP(settings.smtp_host, settings.smtp_port) server = smtplib.SMTP(settings.smtp_host, settings.smtp_port, timeout=timeout)
try: try:
if settings.smtp_use_tls and not settings.smtp_use_ssl: 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_text, "plain", "utf-8"))
msg.attach(MIMEText(body_html, "html", "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"): 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: 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: try:
if self.config.get("smtp_use_tls") and not self.config.get("smtp_use_ssl"): 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_text, "plain", "utf-8"))
msg.attach(MIMEText(body_html, "html", "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: 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: 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: try:
if self.settings.smtp_use_tls and not self.settings.smtp_use_ssl: if self.settings.smtp_use_tls and not self.settings.smtp_use_ssl:

View File

@@ -556,12 +556,16 @@
</button> </button>
</div> </div>
<!-- Local feedback for test email --> <!-- Local feedback for test email -->
<div x-show="testEmailError" x-transition class="mt-3 p-3 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg"> <template x-if="testEmailError">
<p class="text-sm text-red-700 dark:text-red-400" x-text="testEmailError"></p> <div class="mt-3 p-3 bg-red-100 border-2 border-red-500 rounded-lg">
</div> <p class="text-sm text-red-700 font-medium" x-text="testEmailError"></p>
<div x-show="testEmailSuccess" x-transition class="mt-3 p-3 bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg"> </div>
<p class="text-sm text-green-700 dark:text-green-400" x-text="testEmailSuccess"></p> </template>
</div> <template x-if="testEmailSuccess">
<div class="mt-3 p-3 bg-green-100 border-2 border-green-500 rounded-lg">
<p class="text-sm text-green-700 font-medium" x-text="testEmailSuccess"></p>
</div>
</template>
<p class="mt-2 text-xs text-gray-500 dark:text-gray-400"> <p class="mt-2 text-xs text-gray-500 dark:text-gray-400">
Send a test email to verify the platform email configuration is working. Send a test email to verify the platform email configuration is working.
</p> </p>