Add RFC email headers to report messages
This commit is contained in:
@@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
import smtplib
|
||||
from email.message import EmailMessage
|
||||
from email.utils import formatdate, make_msgid, parseaddr
|
||||
from pathlib import Path
|
||||
|
||||
from pve_backup_report.config import EmailConfig
|
||||
@@ -47,6 +48,9 @@ def build_report_message(config: EmailConfig, pdf_path: Path) -> EmailMessage:
|
||||
message["Subject"] = config.subject
|
||||
message["From"] = config.smtp_from or ""
|
||||
message["To"] = ", ".join(config.smtp_to)
|
||||
message["Date"] = formatdate(localtime=True)
|
||||
message["Message-ID"] = make_msgid(domain=message_id_domain(config.smtp_from))
|
||||
message["Auto-Submitted"] = "auto-generated"
|
||||
message.set_content(
|
||||
"Bonjour,\n\n"
|
||||
"Veuillez trouver ci-joint le rapport de sauvegardes Proxmox VE.\n\n"
|
||||
@@ -61,6 +65,16 @@ def build_report_message(config: EmailConfig, pdf_path: Path) -> EmailMessage:
|
||||
return message
|
||||
|
||||
|
||||
def message_id_domain(address: str | None) -> str | None:
|
||||
if address is None:
|
||||
return None
|
||||
parsed_address = parseaddr(address)[1]
|
||||
if "@" not in parsed_address:
|
||||
return None
|
||||
domain = parsed_address.rsplit("@", 1)[1].strip()
|
||||
return domain or None
|
||||
|
||||
|
||||
def authenticate_and_send(
|
||||
smtp: smtplib.SMTP | smtplib.SMTP_SSL,
|
||||
config: EmailConfig,
|
||||
|
||||
Reference in New Issue
Block a user