From 578a90bcc96f937694db840c48bc7dd2ddd8f2ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Wed, 21 Oct 2026 14:08:34 -0300 Subject: [PATCH] fix: e-mails carry a Date header, which spam filters expect Co-Authored-By: Claude Opus 5.5 --- app/mail.py | 4 +++- tests/mail_test.py | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/mail.py b/app/mail.py index 9ac0243..7fa1186 100644 --- a/app/mail.py +++ b/app/mail.py @@ -21,7 +21,7 @@ import os import smtplib import ssl from email.message import EmailMessage -from email.utils import formataddr, make_msgid, parseaddr +from email.utils import formataddr, formatdate, make_msgid, parseaddr ADAPTER = os.environ.get('MAIL_ADAPTER', 'off') RESET_MINUTES = 60 @@ -102,6 +102,8 @@ def message(to, subject, body, html=None): msg['From'] = formataddr((name or 'DTF Dropstar', address)) msg['To'] = to msg['Subject'] = subject + # Neither EmailMessage nor smtplib adds it, and filters (Outlook's among them) count it missing. + msg['Date'] = formatdate(localtime=True) msg['Message-ID'] = make_msgid(domain=address.split('@')[-1] or None) reply = os.environ.get('MAIL_REPLY_TO', '') if reply: diff --git a/tests/mail_test.py b/tests/mail_test.py index 92a01e6..e37a674 100644 --- a/tests/mail_test.py +++ b/tests/mail_test.py @@ -5,6 +5,7 @@ The local stack keeps e-mail in the database (MAIL_ADAPTER=log); the SMTP path is checked against a small SMTP server this test runs itself. """ import email +import email.utils import hashlib import os import re @@ -259,6 +260,7 @@ def smtp_delivery(tag): rcpt, first = sink.messages[0] assert to in rcpt[0] and first['Subject'] == 'Crie uma nova senha · DTF Dropstar' assert first['From'] == 'DTF Dropstar ' + assert first['Date'] and email.utils.parsedate_to_datetime(first['Date']) assert first.get_content().strip() == 'link secreto ção' with db.connect() as c: sent = {r['kind']: r for r in queued(c, to, 'reset') + queued(c, to, 'test') + queued(c, to, 'code')}