changeset 3780:2c187445a3d3

tools (common/email): use `from_email` is specified, always set `email_sender_domain`
author Goffi <goffi@goffi.org>
date Mon, 16 May 2022 13:03:53 +0200
parents 89b13b405b93
children e2a1ac1afb38
files sat/tools/common/email.py
diffstat 1 files changed, 13 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/sat/tools/common/email.py	Mon May 16 13:02:59 2022 +0200
+++ b/sat/tools/common/email.py	Mon May 16 13:03:53 2022 +0200
@@ -43,19 +43,21 @@
     if isinstance(to_emails, str):
         to_emails = to_emails.split()
     email_host = tools_config.getConfig(config, None, "email_server") or "localhost"
-    email_from = tools_config.getConfig(config, None, "email_from")
+    email_from = from_email or tools_config.getConfig(config, None, "email_from")
+
+    # we suppose that email domain and XMPP domain are identical
+    domain = tools_config.getConfig(config, None, "xmpp_domain")
+    if domain is None:
+        if email_from is not None:
+            domain = email_from.split("@", 1)[-1]
+        else:
+            domain = "example.net"
+
     if email_from is None:
-        # we suppose that email domain and XMPP domain are identical
-        domain = tools_config.getConfig(config, None, "xmpp_domain", "example.net")
         email_from = "no_reply@" + domain
-    email_sender_domain = tools_config.getConfig(config, None, "email_sender_domain")
-    if email_sender_domain is None and smtp.DNSNAME == b"localhost.localdomain":
-        try:
-            email_sender_domain = email_from.split('@')[1]
-        except IndexError:
-            log.warning(
-                "Can't set email_sender_domain domain du to invalid email_from: "
-                f"{email_from!r}")
+    email_sender_domain = tools_config.getConfig(
+        config, None, "email_sender_domain", domain
+    )
     email_port = int(tools_config.getConfig(config, None, "email_port", 25))
     email_username = tools_config.getConfig(config, None, "email_username")
     email_password = tools_config.getConfig(config, None, "email_password")