Skip to content
Snippets Groups Projects
Verified Commit 5d4081ec authored by Nicolas KAROLAK's avatar Nicolas KAROLAK
Browse files

handle EMAIL_SMTP_SERVER host:port notation

parent b7c72294
No related branches found
No related tags found
No related merge requests found
......@@ -43,11 +43,13 @@ def check_listen() -> tuple:
return warnings, errors
def check_relay(relay: str, domain: str) -> tuple:
def check_relay(relay_host: str, relay_port: str, domain: str) -> tuple:
"""Check that Postfix is not an open relay.
:param relay: Hostname or IP address of relay host
:type relay: str
:param relay_host: Hostname or IP address of relay host
:type relay_host: str
:param relay_port: Port of relay host
:type relay_port: str
:param domain: Domain name under which mails will be send
:type domain: str
:return: Exit return codes
......@@ -83,6 +85,7 @@ def check_relay(relay: str, domain: str) -> tuple:
u.warning('"myorigin" setting does not contain a valid domain')
warnings += 1
relay = "{}:{}".format(relay_host, relay_port) if relay_port else relay_host
if relay != configured_relay:
u.error("STMP relay must be {}".format(relay))
errors += 1
......@@ -110,8 +113,7 @@ def check_send(sender: str) -> tuple:
if sender:
sender = "-a 'From: {}' ".format(sender)
else:
u.warning("Sender address is not set")
warnings += 1
u.info("Sender address is not set")
cmd = "echo 'test email' | mail -s 'Email used to test configuration.' {}{}".format(
sender, email
)
......@@ -210,12 +212,9 @@ def main():
# get settings
conf = u.load_conf()
relay_host = (
conf.get("EMAIL_SMTP_SERVER", "")
.replace("[", "")
.replace("]", "")
.split(":")[0]
)
relay = conf.get("EMAIL_SMTP_SERVER", "").replace("[", "").replace("]", "")
relay_host = relay.split(":")[0] if ":" in relay else relay
relay_port = relay.split(":")[-1] if ":" in relay else ""
ip_addr = (
(socket.gethostbyname(relay_host) if relay_host else None)
or conf.get("NETWORK_IP_NAT")
......@@ -235,7 +234,7 @@ def main():
errors += check_err if check_err else errors
# check that relayhost is correct
check_warn, check_err = check_relay(relay_host, domain)
check_warn, check_err = check_relay(relay_host, relay_port, domain)
warnings += check_warn if check_warn else warnings
errors += check_err if check_err else errors
......
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