mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-01-19 15:31:20 -05:00
feat: Add Additional SMTP Headers to Decrease Spam Score (#3031)
* add html2text util * add various missing email headers * lint
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user