SIENTIAPDE-1172

fix: add timeout to SMTP connection for improved reliability

- Updated the SMTP connection in the Email class to include a timeout of 20 seconds, enhancing the robustness of email sending operations.
- Adjusted the reconnection logic to maintain consistent timeout settings during server initialization.
This commit is contained in:
vitor-aignosi
2025-07-30 08:55:59 -03:00
parent e75e089b1b
commit ce380bd46d

View File

@@ -30,7 +30,7 @@ class Email(BaseActivity):
logger.info(f"Initializing Email with {smtp_server}:{smtp_port}")
self.server = smtplib.SMTP(smtp_server, smtp_port)
self.server = smtplib.SMTP(smtp_server, smtp_port, timeout=20)
if self.sender_password:
self.server.starttls()
@@ -123,7 +123,8 @@ class Email(BaseActivity):
self.logger.error(f"Failed to quit server: {e}")
raise e
self.server = smtplib.SMTP(self.smtp_server, self.smtp_port)
self.server = smtplib.SMTP(
self.smtp_server, self.smtp_port, timeout=20)
self.server.starttls()
self.server.login(self.sender_email, self.sender_password)
self.server.sendmail(self.sender_email, receivers, msg.as_string())