From c891012fd749f56aeca68d3f3cad325f5ed1ac57 Mon Sep 17 00:00:00 2001 From: Thomas Schneider <thomas@fsmpi.rwth-aachen.de> Date: Fri, 29 Jun 2018 09:30:51 +0200 Subject: [PATCH] Use library-provided methods to generate Message-ID header --- utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/utils.py b/utils.py index 5923bd2..2154c22 100644 --- a/utils.py +++ b/utils.py @@ -7,12 +7,11 @@ import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.mime.application import MIMEApplication +from email.utils import make_msgid from datetime import datetime import requests from io import BytesIO import ipaddress -from socket import getfqdn -from uuid import uuid4 import subprocess import contextlib @@ -59,6 +58,8 @@ class MailManager: self.password = getattr(config, "MAIL_PASSWORD", "") self.use_tls = getattr(config, "MAIL_USE_TLS", True) self.use_starttls = getattr(config, "MAIL_USE_STARTTLS", False) + # if SERVER_NAME is empty, we already have problems elsewhere + self.msgid_domain = getattr(config, "SERVER_NAME") def _get_smtp(self): if self.use_tls: @@ -88,7 +89,7 @@ class MailManager: msg["From"] = self.from_addr msg["To"] = to_addr msg["Subject"] = subject - msg["Message-ID"] = "<{}@{}>".format(uuid4(), getfqdn()) + msg["Message-ID"] = make_msgid(idstring="proto3", domain=self.msgid_domain) if reply_to is not None: msg["Reply-To"] = reply_to msg.attach(MIMEText(content, _charset="utf-8")) -- GitLab