From 391b1b0d2bade688a60048335d29cddd0335ac76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 21 Jan 2018 11:36:47 +0200 Subject: [PATCH] Make sender address configurable, default to trapperkeeper@localhost --- conf/trapperkeeper.yaml | 5 +++++ trapperkeeper/callbacks.py | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/conf/trapperkeeper.yaml b/conf/trapperkeeper.yaml index 0b6012d..8ef69b0 100644 --- a/conf/trapperkeeper.yaml +++ b/conf/trapperkeeper.yaml @@ -44,6 +44,11 @@ defaults: # Type: str recipients: "root@localhost" + # The sender of the message. Defaults to "trapperkeeper@localhost". + # + # Type: str + sender: "trapperkeeper@localhost" + # When running multiple instances of trapperkeeper as a manager for a # given device, the message will be deduplicated in the database. If # you want the e-mail to be sent even when the message has been diff --git a/trapperkeeper/callbacks.py b/trapperkeeper/callbacks.py index 22f667c..ee9e520 100644 --- a/trapperkeeper/callbacks.py +++ b/trapperkeeper/callbacks.py @@ -54,6 +54,7 @@ def _send_mail(self, handler, trap, is_duplicate): recipients = handler["mail"].get("recipients") if not recipients: return + sender = handler["mail"].get("sender", "trapperkeeper@localhost") subject = handler["mail"]["subject"] % { "trap_oid": trap.oid, @@ -64,7 +65,7 @@ def _send_mail(self, handler, trap, is_duplicate): ctxt = dict(trap=trap, dest_host=self.hostname) try: stats.incr("mail_sent_attempted", 1) - send_trap_email(recipients, "trapperkeeper", + send_trap_email(recipients, sender, subject, self.template_env, ctxt) stats.incr("mail_sent_successful", 1) except socket.error as err: