SIENTIAPDE-1172

fix: add conditional login for SMTP server and enhance test coverage

- Updated the Email class to conditionally log in to the SMTP server only if a sender password is provided, improving security.
- Enhanced test cases for the try_send_email method to cover various scenarios, including successful email sending and handling SMTP disconnections.
This commit is contained in:
vitor-aignosi
2025-07-30 09:25:02 -03:00
parent ce380bd46d
commit 3a8eb04462
2 changed files with 89 additions and 10 deletions

View File

@@ -125,8 +125,9 @@ class Email(BaseActivity):
self.server = smtplib.SMTP(
self.smtp_server, self.smtp_port, timeout=20)
self.server.starttls()
self.server.login(self.sender_email, self.sender_password)
if self.sender_password:
self.server.starttls()
self.server.login(self.sender_email, self.sender_password)
self.server.sendmail(self.sender_email, receivers, msg.as_string())
@activity.defn(name="send_email")