Mailer Message-ID in headers

47 views
Skip to first unread message

Jacinto Parga

unread,
May 19, 2025, 6:49:43 AM5/19/25
to py4web
I have sent a message with mailer and got this:

host gmail-smtp-in.l.google.com[64.233.166.27] said:
    550-5.7.1 [82.98.134.111] Messages missing a valid Message-ID header are
    not 550-5.7.1 accepted. For more information, go to 550-5.7.1
    https://support.google.com/mail/?p=RfcMessageNonCompliant and review 550
    5.7.1 RFC 5322 specifications. 5b1f17b1804b1-442f39e6d69si95218285e9.91 -
    gsmtp (in reply to end of DATA command)
  
To fix it when I send a message I just:

from email.utils import make_msgid

def enviar_correo_smtp(destinatario, asunto, mensaje_html):
    try:
        message_id = make_msgid()
        mailer.send(
            to=destinatario,
            subject=asunto,
            body=mensaje_html,
            headers={"Message-ID": message_id},)
        return 200, {"status": "success", "message": "Correo enviado con SMTP"}
    except Exception as e:
        return 500, {"error": str(e)}

But, I suggest making it available to any mail in mailer.py

LN 830 ...  if self.settings.login:
                        server.login(*self.settings.login.split(":", 1))
                    # Add Message-ID si doesn´t exists
                    if "Message-ID" not in payload:
                        payload["Message-ID"] = email.utils.make_msgid()
                    result = server.sendmail(sender, to, payload.as_string())


clement chesnin

unread,
May 19, 2025, 9:56:06 AM5/19/25
to py4web
runned into the same issue, great idea to include it in mailer.py
Reply all
Reply to author
Forward
0 new messages