feat: Add Additional SMTP Headers to Decrease Spam Score (#3031)

* add html2text util

* add various missing email headers

* lint
This commit is contained in:
Michael Genson
2024-01-22 13:40:09 -06:00
committed by GitHub
parent 600c569ae8
commit 702907fc30
3 changed files with 29 additions and 2 deletions

View File

@@ -3,6 +3,10 @@ import typing
from abc import ABC, abstractmethod
from dataclasses import dataclass
from email import message
from email.utils import formatdate
from uuid import uuid4
from html2text import html2text
from mealie.services._base_service import BaseService
@@ -36,7 +40,19 @@ class Message:
msg["Subject"] = self.subject
msg["From"] = f"{self.mail_from_name} <{self.mail_from_address}>"
msg["To"] = to
msg["Date"] = formatdate(localtime=True)
msg.add_alternative(self.html, subtype="html")
msg.add_alternative(html2text(self.html), subtype="plain")
try:
message_id = f"{uuid4()}@{self.mail_from_address.split('@')[1]}"
except IndexError:
# this should never happen with a valid email address,
# but we let the SMTP server handle it instead of raising it here
message_id = f"{uuid4()}@{self.mail_from_address}"
msg["Message-ID"] = message_id
msg["MIME-Version"] = "1.0"
if smtp.ssl:
with smtplib.SMTP_SSL(smtp.host, smtp.port) as server: