fix(projekt-matching): add Date and Message-ID headers to outgoing mail
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import email
|
import email
|
||||||
|
import email.utils
|
||||||
import imaplib
|
import imaplib
|
||||||
import smtplib
|
import smtplib
|
||||||
import ssl
|
import ssl
|
||||||
@@ -71,6 +72,8 @@ class MailBox:
|
|||||||
def send_mail(user, password, to, subject, body):
|
def send_mail(user, password, to, subject, body):
|
||||||
msg = EmailMessage()
|
msg = EmailMessage()
|
||||||
msg["From"], msg["To"], msg["Subject"] = user, to, subject
|
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)
|
msg.set_content(body)
|
||||||
with smtplib.SMTP(SMTP_HOST, SMTP_PORT, timeout=30) as server:
|
with smtplib.SMTP(SMTP_HOST, SMTP_PORT, timeout=30) as server:
|
||||||
server.starttls(context=ssl.create_default_context())
|
server.starttls(context=ssl.create_default_context())
|
||||||
|
|||||||
@@ -51,3 +51,5 @@ def test_send_mail_starttls():
|
|||||||
server.login.assert_called_once_with("u@x", "pw")
|
server.login.assert_called_once_with("u@x", "pw")
|
||||||
msg = server.send_message.call_args.args[0]
|
msg = server.send_message.call_args.args[0]
|
||||||
assert msg["Subject"] == "Subj" and msg["To"] == "to@x"
|
assert msg["Subject"] == "Subj" and msg["To"] == "to@x"
|
||||||
|
assert msg["Date"]
|
||||||
|
assert msg["Message-ID"].endswith("@destengs.com>")
|
||||||
|
|||||||
Reference in New Issue
Block a user