From c516c89905ff96bfa75fdf675b20c44a4989bb23 Mon Sep 17 00:00:00 2001 From: "Pamela R. Hunt" <90120449+unsocial-bleach@users.noreply.github.com> Date: Sat, 18 Dec 2021 23:17:02 +0000 Subject: [PATCH] Add config option to disable SMTP auth for basic postfix setup (#314) Sometimes it is useful to disable SMTP authentication for sending emails. For example, if someone is using a local postfix server, the default install doesn't require/enable auth. When this new config option is set to enable_smtp_auth: false, the username_smtp and password_smtp config options are ignored. --- config-example.yaml | 1 + src/notifier/smtp_notifier.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/config-example.yaml b/config-example.yaml index 169b895..4b1fa8e 100644 --- a/config-example.yaml +++ b/config-example.yaml @@ -79,6 +79,7 @@ notifier: recipient: 'you@example.com' username_smtp: 'username' password_smtp: 'password' + enable_smtp_auth: true host: 'smtp.example.com' port: 587 script: diff --git a/src/notifier/smtp_notifier.py b/src/notifier/smtp_notifier.py index 6730a92..ac2305e 100644 --- a/src/notifier/smtp_notifier.py +++ b/src/notifier/smtp_notifier.py @@ -24,6 +24,7 @@ def __init__(self, title_prefix: str, config: dict): self.password_smtp = credentials["password_smtp"] self.host = credentials["host"] self.port = credentials["port"] + self.enable_smtp_auth = credentials.get("enable_smtp_auth", True) except KeyError as key: logging.error(f"Invalid config.yaml. Missing key: {key}") @@ -57,7 +58,8 @@ def send_events_to_user(self, events: List[Event]) -> bool: server.starttls() # stmplib docs recommend calling ehlo() before & after starttls() server.ehlo() - server.login(self.username_smtp, self.password_smtp) + if self.enable_smtp_auth: + server.login(self.username_smtp, self.password_smtp) server.sendmail(self.sender, self.recipient, msg.as_string()) server.quit() # Display an error message if something goes wrong.