Skip to content

Commit

Permalink
Add config option to disable SMTP auth for basic postfix setup (#314)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
unsocial-bleach authored and martomi committed Jul 2, 2022
1 parent aede9f3 commit c516c89
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions config-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ notifier:
recipient: '[email protected]'
username_smtp: 'username'
password_smtp: 'password'
enable_smtp_auth: true
host: 'smtp.example.com'
port: 587
script:
Expand Down
4 changes: 3 additions & 1 deletion src/notifier/smtp_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit c516c89

Please sign in to comment.