fix(projekt-matching): add Date and Message-ID headers to outgoing mail

This commit is contained in:
tlg
2026-07-09 15:06:55 +02:00
parent 79966e6e54
commit cf088f0bd3
2 changed files with 5 additions and 0 deletions

View File

@@ -2,6 +2,7 @@
from __future__ import annotations
import email
import email.utils
import imaplib
import smtplib
import ssl
@@ -71,6 +72,8 @@ class MailBox:
def send_mail(user, password, to, subject, body):
msg = EmailMessage()
msg["From"], msg["To"], msg["Subject"] = user, to, subject
msg["Date"] = email.utils.formatdate(localtime=True)
msg["Message-ID"] = email.utils.make_msgid(domain="destengs.com")
msg.set_content(body)
with smtplib.SMTP(SMTP_HOST, SMTP_PORT, timeout=30) as server:
server.starttls(context=ssl.create_default_context())

View File

@@ -51,3 +51,5 @@ def test_send_mail_starttls():
server.login.assert_called_once_with("u@x", "pw")
msg = server.send_message.call_args.args[0]
assert msg["Subject"] == "Subj" and msg["To"] == "to@x"
assert msg["Date"]
assert msg["Message-ID"].endswith("@destengs.com>")