From 9b45fef76bb1198cb1e7959e170b755564d12c59 Mon Sep 17 00:00:00 2001 From: Andon Andonov Date: Mon, 10 Jul 2023 11:38:05 +0300 Subject: [PATCH] vdk-core: Set sender when checking if email exists Currently, when a target email address is checked if exists, we set a dummy sender `"whatever"`. This works in cases, where the smtp server does not enforce validation checks on the sender. It does not, however, work in cases when the smtp server uses TLS (like Office365). In such cases, the check of the target email address fails with Status `503: Bad sequence of commands`, because the `.mail("whatever")` method call sets the **FROM** field to *mail FROM:*, and this causes the smtp server to return `501 5.1.7 Invalid address`. This change replces `"whatever"` with the actual sender address used to send the email notifications (set through the `VDK_NOTIFICATION_SENDER`) environment variable. Testing Done: Create a sample email script to first better understand the error, and second to verify that the fix actually works. Script is: ```python HOST = "smtp.office365.com" PORT = 587 SENDER = "" USERNAME = "" PASSWORD = "" TARGET_ADDRESS = "" s = smtplib.SMTP(HOST, PORT) s.starttls() s.login(USERNAME, PASSWORD) s.set_debuglevel(1) try: s.helo() # s.mail(SENDER) # Test the actual fix s.mail("whatever") # Check the full error resp = s.rcpt(TARGET_ADDRESS) print(resp) except smtplib.SMTPServerDisconnected as e: print(f"SMTP connection error while checking if email address exists: {e}") finally: s.quit() ``` Signed-off-by: Andon Andonov --- .../internal/builtin_plugins/notification/notification_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/vdk-core/src/vdk/internal/builtin_plugins/notification/notification_base.py b/projects/vdk-core/src/vdk/internal/builtin_plugins/notification/notification_base.py index aff05eb002..4500410e18 100644 --- a/projects/vdk-core/src/vdk/internal/builtin_plugins/notification/notification_base.py +++ b/projects/vdk-core/src/vdk/internal/builtin_plugins/notification/notification_base.py @@ -123,7 +123,7 @@ def _email_address_exists(self, email_address): s = self.__smtp_server() try: s.helo() - s.mail("whatever") + s.mail(self._sender) resp = s.rcpt(email_address) return resp[0] == 250 except smtplib.SMTPServerDisconnected as e: