From 48333e80402596cd3da96f3a3764e59de04cabfc Mon Sep 17 00:00:00 2001 From: Adrian Amaglio Date: Wed, 16 Sep 2020 15:14:26 +0200 Subject: [PATCH] Date header added --- main.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index e5626cf..d22dee3 100755 --- a/main.py +++ b/main.py @@ -4,6 +4,7 @@ response = bottle.response import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart +from email.message import EmailMessage import os # for environ vars import sys # to print ot stderr import re # to match our template system @@ -12,6 +13,7 @@ from dotenv import load_dotenv import random, string # for tokens import html # for sanitization from bson.json_util import dumps +import datetime # For email date ##################################################### Bottle stuff ############################################ @@ -189,14 +191,17 @@ def fill_fields(request, fields): raise MissingParameterException("Le champs {} est obligatoire".format(field)) return fields -def send_mail(from_address, to, subject, content): +def send_mail (from_address, to, subject, content): """Actually connect to smtp server, build a message object and send it as a mail""" - msg = MIMEMultipart() + msg = EmailMessage() msg['From'] = smtp_server_sender msg.add_header('reply-to', from_address) msg['To'] = to msg['Subject'] = subject - msg.attach(MIMEText(content, 'plain', "utf-8")) + msg['Date'] = datetime.datetime.now() + msg.set_content(MIMEText(content, 'plain', "utf-8")) + #or + #msg.set_content(content) # SMTP preambles if security == 'ssl':