From 8c7a74822288f676be4cc1a1bba25db67146a124 Mon Sep 17 00:00:00 2001 From: Yannik Schmidt Date: Sat, 17 Feb 2024 18:07:32 +0100 Subject: [PATCH] fix: misc smtp login & error reporting fixes --- client/dispatch-query.py | 9 +++++++-- client/smtphelper.py | 7 ++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/client/dispatch-query.py b/client/dispatch-query.py index 46a4735..1f8a438 100755 --- a/client/dispatch-query.py +++ b/client/dispatch-query.py @@ -26,10 +26,15 @@ def debug_send(uuid, data, fail_it=False): def email_send(dispatch_uuid, email_address, message, smtp_target, smtp_user, smtp_pass): '''Send message via email''' - + + if not email_address: + print("Missing E-Mail Address for STMP send", file=sys.stderr) + report_failed_dispatch(dispatch_uuid, "Missing email-field in dispatch infor") + return + subject = "Atlantis Dispatch" smtphelper.smtp_send(smtp_target, smtp_user, smtp_pass, email_address, subject, message) - report_failed_dispatch(uuid, "Email dispatch not yet implemented") + confirm_dispatch(dispatch_uuid) def ntfy_api_get_topic(ntfy_api_server, ntfy_api_token, username): '''Get the topic of the user''' diff --git a/client/smtphelper.py b/client/smtphelper.py index 3355328..f5e3df8 100644 --- a/client/smtphelper.py +++ b/client/smtphelper.py @@ -28,7 +28,12 @@ def smtp_send(server, user, password, recipient, subject, body): # Establish a connection to the SMTP server server = smtplib.SMTP(smtp_server, smtp_port) server.starttls() # Secure the connection - server.login(sender_email, sender_password) + + # fix login user if necessary # + sender_user = sender_email + if "@" in sender_email: + sender_user = sender_email.split("@")[0] + server.login(sender_user, sender_password) # Send the email server.sendmail(sender_email, recipient_email, message.as_string())