From b61d1dd8e2433dfc4cb5eee6bda935b52bb9346d Mon Sep 17 00:00:00 2001 From: Stefan Sterz Date: Wed, 26 Oct 2022 14:05:29 +0200 Subject: [PATCH] fix: add a message id and html body to reduce spam score these changes should lower the spam score for systems that use e.g. spamassassin and increase the likelihood of the email being delivered. --- wichteln.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/wichteln.py b/wichteln.py index 89f0a2b..64a2d6d 100755 --- a/wichteln.py +++ b/wichteln.py @@ -11,7 +11,7 @@ buy presents for. from argparse import ArgumentParser from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText -from email.utils import formatdate +from email.utils import formatdate, make_msgid import json import random import smtplib @@ -79,12 +79,31 @@ for r in participants: msg['From'] = config['sender'] msg['To'] = r['mail'] msg['Subject'] = 'Wichteln 🎄' + msg['Message-ID'] = make_msgid(domain=config['sender'] + .split('@')[1] + .strip('>')) msg['Date'] = formatdate(localtime=True) body = 'Lieb'+r['gender']+' '+r['name']+'!\n\n' body += 'Du bist heuer Wichtel für '+r['partner']+'.\n' body += 'Das Geschenk sollte nicht mehr als 50€ kosten.\n\n' body += 'Frohe Weihnachten!\n— Dein Christkind 👼' + + html = f""" + + + +

Lieb{r['gender']} {r['name']}!

+ Du bist heuer Wichtel für {r['partner']}.
+ Das Geschenk sollte nicht mehr als 50€ kosten.

+ Frohe Weihnachten!
+ — Dein Christkind 👼 +

+ + +""" msg.attach(MIMEText(body, 'plain', 'utf-8')) + msg.attach(MIMEText(html, 'html', 'utf-8')) + print("Sending email to", r['name']) server.sendmail(config['sender'], r['mail'], msg.as_string())