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.
This commit is contained in:
Shannon Sterz 2022-10-26 14:05:29 +02:00
parent fd0e30bca2
commit b61d1dd8e2
Signed by: sterzy
GPG key ID: 2370EE3A271DF05B

View file

@ -11,7 +11,7 @@ buy presents for.
from argparse import ArgumentParser from argparse import ArgumentParser
from email.mime.multipart import MIMEMultipart from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText from email.mime.text import MIMEText
from email.utils import formatdate from email.utils import formatdate, make_msgid
import json import json
import random import random
import smtplib import smtplib
@ -79,6 +79,9 @@ for r in participants:
msg['From'] = config['sender'] msg['From'] = config['sender']
msg['To'] = r['mail'] msg['To'] = r['mail']
msg['Subject'] = 'Wichteln 🎄' msg['Subject'] = 'Wichteln 🎄'
msg['Message-ID'] = make_msgid(domain=config['sender']
.split('@')[1]
.strip('>'))
msg['Date'] = formatdate(localtime=True) msg['Date'] = formatdate(localtime=True)
body = 'Lieb'+r['gender']+' '+r['name']+'!\n\n' body = 'Lieb'+r['gender']+' '+r['name']+'!\n\n'
@ -86,5 +89,21 @@ for r in participants:
body += 'Das Geschenk sollte nicht mehr als 50€ kosten.\n\n' body += 'Das Geschenk sollte nicht mehr als 50€ kosten.\n\n'
body += 'Frohe Weihnachten!\n— Dein Christkind 👼' body += 'Frohe Weihnachten!\n— Dein Christkind 👼'
html = f"""
<html>
<head></head>
<body>
<p>Lieb{r['gender']} {r['name']}!<br><br>
Du bist heuer Wichtel für {r['partner']}.<br>
Das Geschenk sollte nicht mehr als 50 kosten.<br><br>
Frohe Weihnachten!<br>
Dein Christkind 👼
</p>
</body>
</html>
"""
msg.attach(MIMEText(body, 'plain', 'utf-8')) 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()) server.sendmail(config['sender'], r['mail'], msg.as_string())