Skip to content
Snippets Groups Projects
Commit db8d9a89 authored by Stéphane Diemer's avatar Stéphane Diemer
Browse files

Use email sender config in email test (refs #26619).

parent 7a1a8785
No related branches found
No related tags found
No related merge requests found
......@@ -20,7 +20,7 @@ except ImportError:
import spf
# install netstat if not present
if subprocess.call(["which", "netstat"]) != 0:
if subprocess.call(["which", "netstat"], stdout=subprocess.DEVNULL) != 0:
subprocess.check_call(["apt-get", "-qq", "-y", "install", "net-tools"])
sys.path.append(str(Path(__file__).parents[1].resolve()))
......@@ -66,7 +66,7 @@ def check_relay(conf: dict) -> int:
if status == 0:
configured_relay = (
out[len("relayhost") :].strip(" \t=").replace("[", "").replace("]", "")
out[len("relayhost"):].strip(" \t=").replace("[", "").replace("]", "")
)
else:
configured_relay = ""
......@@ -102,7 +102,7 @@ def check_relay(conf: dict) -> int:
return 0
def check_send_test_email() -> int:
def check_send_test_email(conf: dict) -> int:
"""Check that Postfix can send email.
:return: Exit return code
......@@ -111,10 +111,23 @@ def check_send_test_email() -> int:
print("Checking Postfix can send email:")
# check if s-nail is installed, if not set from address
sender = ""
status, out = subprocess.getstatusoutput("dpkg -l s-nail | grep -E '^ii'")
if status == 0:
u.warning("The package 's-nail' is installed, the email sender address will be ignored.")
else:
sender = conf.get("EMAIL_SENDER") or ""
# send email
email = "noreply+{}-{}@ubicast.eu".format(time.time(), random.randint(0, 1000))
u.info("Sending test email to '{}'".format(email))
cmd = "echo 'test email' | mail -s 'test email' {}".format(email)
if sender:
u.info("Sender address is '{}'".format(sender))
sender = "-a 'From: {}' ".format(sender)
else:
u.info("Sender address is not set")
cmd = "echo 'test email' | mail -s 'Email used to test configuration.' {}{}".format(sender, email)
subprocess.getstatusoutput(cmd)
# init vars
......@@ -182,7 +195,7 @@ def main():
rcode = check_listen()
if rcode == 0:
rcode = check_relay(conf)
if check_send_test_email() == 1:
if check_send_test_email(conf) == 1:
rcode = 1
sys.exit(rcode)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment