diff --git a/mealie/services/email/email_senders.py b/mealie/services/email/email_senders.py index 370441c59efb..ecb840c6f9c5 100644 --- a/mealie/services/email/email_senders.py +++ b/mealie/services/email/email_senders.py @@ -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: diff --git a/poetry.lock b/poetry.lock index 6b982c68b841..c3e40c30621a 100644 --- a/poetry.lock +++ b/poetry.lock @@ -708,6 +708,17 @@ files = [ [package.dependencies] lxml = "*" +[[package]] +name = "html2text" +version = "2020.1.16" +description = "Turn HTML into equivalent Markdown-structured text." +optional = false +python-versions = ">=3.5" +files = [ + {file = "html2text-2020.1.16-py3-none-any.whl", hash = "sha256:c7c629882da0cf377d66f073329ccf34a12ed2adf0169b9285ae4e63ef54c82b"}, + {file = "html2text-2020.1.16.tar.gz", hash = "sha256:e296318e16b059ddb97f7a8a1d6a5c1d7af4544049a01e261731d2d5cc277bbb"}, +] + [[package]] name = "html5lib" version = "1.1" @@ -2013,7 +2024,6 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, - {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"}, {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, @@ -2938,4 +2948,4 @@ pgsql = ["psycopg2-binary"] [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "3af89a4b335d71028761cbd6c2293eda5dbd0d0518d1dacd60440ef5401ba873" +content-hash = "80b15507db71f3e7f66c8391405aa2a47f901fb94296006495ed47027ee8d88d" diff --git a/pyproject.toml b/pyproject.toml index 0dd50d1112d1..602115a892ad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,6 +44,7 @@ beautifulsoup4 = "^4.11.2" isodate = "^0.6.1" text-unidecode = "^1.3" rapidfuzz = "^3.2.0" +html2text = "^2020.1.16" [tool.poetry.group.dev.dependencies] black = "^23.7.0"