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:
+6
-2
@@ -181,10 +181,14 @@ def send_email(png: bytes, label: str) -> None:
|
|||||||
print("E-Mail-Konfiguration unvollständig – Mail wird nicht gesendet.")
|
print("E-Mail-Konfiguration unvollständig – Mail wird nicht gesendet.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# multipart/related: HTML + CID-Bild werden als Einheit behandelt
|
||||||
|
related = MIMEMultipart("related")
|
||||||
|
|
||||||
msg = MIMEMultipart("mixed")
|
msg = MIMEMultipart("mixed")
|
||||||
msg["Subject"] = f"{MAIL_SUBJECT} – {label}"
|
msg["Subject"] = f"{MAIL_SUBJECT} – {label}"
|
||||||
msg["From"] = MAIL_FROM
|
msg["From"] = MAIL_FROM
|
||||||
msg["To"] = ", ".join(MAIL_TO)
|
msg["To"] = ", ".join(MAIL_TO)
|
||||||
|
msg.attach(related)
|
||||||
|
|
||||||
body = MIMEText(
|
body = MIMEText(
|
||||||
f"<html><body>"
|
f"<html><body>"
|
||||||
@@ -193,12 +197,12 @@ def send_email(png: bytes, label: str) -> None:
|
|||||||
f"</body></html>",
|
f"</body></html>",
|
||||||
"html",
|
"html",
|
||||||
)
|
)
|
||||||
msg.attach(body)
|
related.attach(body)
|
||||||
|
|
||||||
img = MIMEImage(png, name="wetterbericht.png")
|
img = MIMEImage(png, name="wetterbericht.png")
|
||||||
img.add_header("Content-ID", "<chart@weather>")
|
img.add_header("Content-ID", "<chart@weather>")
|
||||||
img.add_header("Content-Disposition", "inline", filename="wetterbericht.png")
|
img.add_header("Content-Disposition", "inline", filename="wetterbericht.png")
|
||||||
msg.attach(img)
|
related.attach(img)
|
||||||
|
|
||||||
with smtplib.SMTP(MAIL_SERVER, MAIL_PORT) as smtp:
|
with smtplib.SMTP(MAIL_SERVER, MAIL_PORT) as smtp:
|
||||||
smtp.ehlo()
|
smtp.ehlo()
|
||||||
|
|||||||
Reference in New Issue
Block a user