Fix: Bild erschien doppelt in der Mail

multipart/mixed mit CID-Referenz ließ Mail-Clients das Bild inline
und als Anhang rendern. Korrektur auf multipart/related als Container
für HTML + Bild.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
rxf
2026-05-26 11:23:13 +02:00
parent e1bda88ab4
commit 0a30d79f71
+6 -2
View File
@@ -181,10 +181,14 @@ def send_email(png: bytes, label: str) -> None:
print("E-Mail-Konfiguration unvollständig Mail wird nicht gesendet.")
return
# multipart/related: HTML + CID-Bild werden als Einheit behandelt
related = MIMEMultipart("related")
msg = MIMEMultipart("mixed")
msg["Subject"] = f"{MAIL_SUBJECT} {label}"
msg["From"] = MAIL_FROM
msg["To"] = ", ".join(MAIL_TO)
msg.attach(related)
body = MIMEText(
f"<html><body>"
@@ -193,12 +197,12 @@ def send_email(png: bytes, label: str) -> None:
f"</body></html>",
"html",
)
msg.attach(body)
related.attach(body)
img = MIMEImage(png, name="wetterbericht.png")
img.add_header("Content-ID", "<chart@weather>")
img.add_header("Content-Disposition", "inline", filename="wetterbericht.png")
msg.attach(img)
related.attach(img)
with smtplib.SMTP(MAIL_SERVER, MAIL_PORT) as smtp:
smtp.ehlo()