modified: web/blueprints/group_admin.py
modified: web/blueprints/site_admin.py modified: web/config.py new file: web/mailer.py modified: web/panel_db.py modified: web/templates/admin/base.html modified: web/templates/admin/dashboard.html new file: web/templates/admin/mail_settings.html
This commit is contained in:
27
web/mailer.py
Normal file
27
web/mailer.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import smtplib
|
||||
from email.message import EmailMessage
|
||||
|
||||
from config import Config
|
||||
|
||||
|
||||
def build_from_header(from_email: str, from_name: str | None = None) -> str:
|
||||
if from_name:
|
||||
return f"{from_name} <{from_email}>"
|
||||
return from_email
|
||||
|
||||
|
||||
|
||||
def send_mail(settings: dict, recipient: str, subject: str, text_body: str):
|
||||
msg = EmailMessage()
|
||||
msg["Subject"] = subject
|
||||
msg["From"] = build_from_header(settings["from_email"], settings.get("from_name"))
|
||||
msg["To"] = recipient
|
||||
msg.set_content(text_body)
|
||||
|
||||
with smtplib.SMTP(settings["host"], settings["port"], timeout=Config.MAIL_TIMEOUT) as smtp:
|
||||
smtp.ehlo()
|
||||
if settings.get("use_tls", True):
|
||||
smtp.starttls()
|
||||
smtp.ehlo()
|
||||
smtp.login(settings["username"], settings["password"])
|
||||
smtp.send_message(msg)
|
||||
Reference in New Issue
Block a user