modified: web/blueprints/group_admin.py

modified:   web/blueprints/site_admin.py
	modified:   web/mailer.py
This commit is contained in:
SimolZimol
2026-04-13 19:10:21 +02:00
parent ee66a04cb2
commit 8f614a08cc
3 changed files with 18 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
import smtplib
from html import escape
from email.message import EmailMessage
from email.utils import formatdate, make_msgid
from config import Config
@@ -11,6 +12,12 @@ def build_from_header(from_email: str, from_name: str | None = None) -> str:
return from_email
def force_https_url(url: str) -> str:
if url.startswith("http://"):
return "https://" + url[len("http://"):]
return url
def build_invite_email(
username: str,
invite_url: str,
@@ -85,6 +92,9 @@ def send_mail(settings: dict, recipient: str, subject: str, text_body: str, html
msg["Subject"] = subject
msg["From"] = build_from_header(settings["from_email"], settings.get("from_name"))
msg["To"] = recipient
msg["Date"] = formatdate(localtime=True)
sender_domain = (settings.get("from_email", "noreply@example.com").split("@")[-1] or "example.com")
msg["Message-ID"] = make_msgid(domain=sender_domain)
msg.set_content(text_body)
if html_body:
msg.add_alternative(html_body, subtype="html")