-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plugin was attemtping SMTP connections regardless of if the plugin config was using defaults. Now checks on pre/post checks to stop attempted SMTP connections before the plugin was disabled. Signed-off-by: <[email protected]>
- Loading branch information
1 parent
4c590e2
commit cff205c
Showing
1 changed file
with
15 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ def initialize(self): | |
settings.register_option( | ||
section="plugins.mail", | ||
key="recipient", | ||
default="[email protected]", | ||
default=None, | ||
help_msg=help_msg, | ||
) | ||
|
||
|
@@ -38,31 +38,31 @@ def initialize(self): | |
settings.register_option( | ||
section="plugins.mail", | ||
key="sender", | ||
default="[email protected]", | ||
default=None, | ||
help_msg=help_msg, | ||
) | ||
|
||
help_msg = "Mail server." | ||
settings.register_option( | ||
section="plugins.mail", | ||
key="server", | ||
default="localhost", | ||
default=None, | ||
help_msg=help_msg, | ||
) | ||
|
||
help_msg = "Mail server port." | ||
settings.register_option( | ||
section="plugins.mail", | ||
key="port", | ||
default=587, | ||
default=None, | ||
help_msg=help_msg, | ||
) | ||
|
||
help_msg = "Mail server Application Password." | ||
settings.register_option( | ||
section="plugins.mail", | ||
key="password", | ||
default="", | ||
default=None, | ||
help_msg=help_msg, | ||
) | ||
|
||
|
@@ -160,6 +160,10 @@ def _send_email(smtp, sender, rcpt, msg): | |
|
||
@staticmethod | ||
def _smtp_login_and_send(job, msg): | ||
if not job.config.get("plugins.mail.server"): | ||
job_log.error("SMTP server not configured. Plugin Disabled.") | ||
return False | ||
|
||
server, port, sender, password = Mail._get_smtp_config(job) | ||
smtp = Mail._create_smtp_connection(server, port) | ||
if smtp: | ||
|
@@ -257,6 +261,7 @@ def _get_test_summary(job): | |
|
||
def pre(self, job): | ||
if not self.enabled: | ||
job_log.info("Email plugin disabled, skipping start notification.") | ||
return | ||
|
||
phase = "Start" | ||
|
@@ -268,6 +273,9 @@ def pre(self, job): | |
|
||
def post(self, job): | ||
if not self.enabled or not self.start_email_sent: | ||
job_log.info( | ||
"Email plugin disabled or start email not sent, skipping end notification." | ||
) | ||
return | ||
|
||
phase = "Post" | ||
|
@@ -285,14 +293,10 @@ def post(self, job): | |
def _validate_email_config(self, job): | ||
required_keys = ["recipient", "sender", "server", "port"] | ||
for key in required_keys: | ||
if not job.config.get(f"plugins.mail.{key}"): | ||
if job.config.get(f"plugins.mail.{key}") is None: | ||
job_log.error( | ||
f"Email configuration {key} is missing. Disabling Plugin." | ||
f"Email configuration {key} is missing or set to None. Disabling Plugin." | ||
) | ||
return False | ||
|
||
if job.config.get("plugins.mail.sender") == "[email protected]": | ||
job_log.error("Email sender is still set to default. Disabling Plugin.") | ||
return False | ||
|
||
return True |