From bdc13f92382b2097c0cb72050bfdaf219afc4888 Mon Sep 17 00:00:00 2001 From: Laurent Magnien Date: Sat, 9 Mar 2024 02:11:03 +0100 Subject: [PATCH] SMTP authentication is optional (#2765) Co-authored-by: Laurent Magnien --- api/extensions/ext_mail.py | 2 -- api/libs/smtp.py | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/api/extensions/ext_mail.py b/api/extensions/ext_mail.py index 87b15697ba1995..d2c6e32dfd1b54 100644 --- a/api/extensions/ext_mail.py +++ b/api/extensions/ext_mail.py @@ -32,8 +32,6 @@ def init_app(self, app: Flask): from libs.smtp import SMTPClient if not app.config.get('SMTP_SERVER') or not app.config.get('SMTP_PORT'): raise ValueError('SMTP_SERVER and SMTP_PORT are required for smtp mail type') - if not app.config.get('SMTP_USERNAME') or not app.config.get('SMTP_PASSWORD'): - raise ValueError('SMTP_USERNAME and SMTP_PASSWORD are required for smtp mail type') self._client = SMTPClient( server=app.config.get('SMTP_SERVER'), port=app.config.get('SMTP_PORT'), diff --git a/api/libs/smtp.py b/api/libs/smtp.py index 17fcc6de7c2353..6c8e0c2777c685 100644 --- a/api/libs/smtp.py +++ b/api/libs/smtp.py @@ -16,7 +16,8 @@ def send(self, mail: dict): smtp = smtplib.SMTP(self.server, self.port) if self._use_tls: smtp.starttls() - smtp.login(self.username, self.password) + if (self.username): + smtp.login(self.username, self.password) msg = MIMEMultipart() msg['Subject'] = mail['subject'] msg['From'] = self._from