From 648be8502a6e2f223de2d5a228828f519d2ec1b2 Mon Sep 17 00:00:00 2001 From: ducnt69 Date: Thu, 28 Nov 2024 14:52:58 +0700 Subject: [PATCH 1/3] Add some config to custom SMTP server --- arbiter/actions.py | 7 ++++++- arbiter/cfgparser.py | 2 ++ etc/config.toml | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/arbiter/actions.py b/arbiter/actions.py index e1b197f..8259e66 100644 --- a/arbiter/actions.py +++ b/arbiter/actions.py @@ -296,9 +296,14 @@ def send_email(subject, html_message, to, bcc, sender, image_attachment=None, # Send the message if email["bcc"] or email["to"]: - mail_server = cfg.email.mail_server + mail_server = cfg.email.mail_server + smtp_starttls = cfg.email.smtp_starttls + smtp_passwd = cfg.email.smtp_passwd try: with smtplib.SMTP(mail_server) as smtp: + if (smtp_starttls == True and smtp_passwd != ''): + smtp.starttls() # Start TLS encryption + smtp.login(email["From"], smtp_passwd) # Login smtp.send_message(email) except Exception as err: logger.debug(err) diff --git a/arbiter/cfgparser.py b/arbiter/cfgparser.py index 3a8255f..764fb25 100755 --- a/arbiter/cfgparser.py +++ b/arbiter/cfgparser.py @@ -379,6 +379,8 @@ def redacted_url(url): "email": { "email_domain": ValidationProtocol(str), "from_email": ValidationProtocol(str), + "smtp_passwd": ValidationProtocol(str,default_value=""), + "smtp_starttls": ValidationProtocol(bool,default_value=False), "admin_emails": ValidationProtocol(list, all_are_str), "mail_server": ValidationProtocol(str, can_ping), "keep_plots": ValidationProtocol(bool), diff --git a/etc/config.toml b/etc/config.toml index 0dd16eb..2c1066e 100644 --- a/etc/config.toml +++ b/etc/config.toml @@ -21,6 +21,8 @@ time_to_min_bad = 1800 # 30 minutes [email] email_domain = 'organization.edu' # Used for a generic email addr integration in integrations.py from_email = 'noreply+arbiter@organization.edu' +smtp_passwd = '' # Used to login +smtp_starttls = true # default false admin_emails = ['john.doe@organization.edu'] mail_server = '0.0.0.0' keep_plots = false From 1d60ae7769557d475c6b290cde54987484b84ce0 Mon Sep 17 00:00:00 2001 From: ducnt69 Date: Thu, 28 Nov 2024 17:03:43 +0700 Subject: [PATCH 2/3] Edit format email v. for vinai.io --- etc/integrations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/integrations.py b/etc/integrations.py index 5b151c4..7ec2173 100644 --- a/etc/integrations.py +++ b/etc/integrations.py @@ -310,7 +310,7 @@ def email_addr_placeholder(username): username: str The username of the user. """ - return ("{}@" + cfg.email.email_domain).format(username) + return ("v.{}@" + cfg.email.email_domain).format(username) def _get_name(uid): From 32097aecbf8260c1b9ac2b394e54e1d66beb562b Mon Sep 17 00:00:00 2001 From: ducnt69 Date: Tue, 3 Dec 2024 16:23:22 +0700 Subject: [PATCH 3/3] Add comment for smtp configure --- etc/config.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/etc/config.toml b/etc/config.toml index 2c1066e..1e425a2 100644 --- a/etc/config.toml +++ b/etc/config.toml @@ -21,8 +21,8 @@ time_to_min_bad = 1800 # 30 minutes [email] email_domain = 'organization.edu' # Used for a generic email addr integration in integrations.py from_email = 'noreply+arbiter@organization.edu' -smtp_passwd = '' # Used to login -smtp_starttls = true # default false +smtp_passwd = '' # Password used for logging in to the SMTP server with from_email and smtp_passwd. +smtp_starttls = True # If True, enables STARTTLS to secure the SMTP connection. Default is False. admin_emails = ['john.doe@organization.edu'] mail_server = '0.0.0.0' keep_plots = false