chore: add implicit TLS support for email

This commit is contained in:
Daan Selen
2026-01-14 23:45:42 +01:00
parent cb0619036f
commit b6e2f084e6
75 changed files with 111 additions and 92 deletions

View File

@@ -1,4 +1,5 @@
import os.path
import ssl
import smtplib
# Email libaries
@@ -8,6 +9,8 @@ from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.utils import formatdate
from flask import current_app
class EmailSender:
def __init__(self, DashboardConfig):
self.DashboardConfig = DashboardConfig
@@ -17,7 +20,7 @@ class EmailSender:
self.refresh_vals()
def refresh_vals(self):
def refresh_vals(self) -> None:
self.Server = self.DashboardConfig.GetConfig("Email", "server")[1]
self.Port = self.DashboardConfig.GetConfig("Email", "port")[1]
@@ -69,12 +72,16 @@ class EmailSender:
smtp = None
try:
smtp = smtplib.SMTP(self.Server, port=int(self.Port))
context = ssl.create_default_context()
if self.Encryption == "IMPLICITTLS":
smtp = smtplib.SMTP_SSL(self.Server, port=int(self.Port), context=context)
else:
smtp = smtplib.SMTP(self.Server, port=int(self.Port))
smtp.ehlo()
# Configure SMTP encryption type
if self.Encryption == "STARTTLS":
smtp.starttls()
smtp.starttls(context=context)
smtp.ehlo()
# Log into the SMTP server if required
@@ -90,4 +97,7 @@ class EmailSender:
finally:
if smtp:
smtp.quit()
try:
smtp.quit()
except Exception:
pass