Commit c891012f authored by Thomas Schneider's avatar Thomas Schneider

Use library-provided methods to generate Message-ID header

parent 0b81e059
......@@ -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"))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment