diff --git a/app/services/email_service.py b/app/services/email_service.py index 3a0f514e..238f2fc9 100644 --- a/app/services/email_service.py +++ b/app/services/email_service.py @@ -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: diff --git a/app/templates/admin/settings.html b/app/templates/admin/settings.html index 6288a290..f15c555f 100644 --- a/app/templates/admin/settings.html +++ b/app/templates/admin/settings.html @@ -556,12 +556,16 @@ -
-

-
-
-

-
+ +

Send a test email to verify the platform email configuration is working.