From a4c1bd071ba48f1a27c73ee4847fa38a1b8ca62b Mon Sep 17 00:00:00 2001 From: Yannik Schmidt Date: Tue, 6 Oct 2020 16:36:10 +0200 Subject: [PATCH] fix mail formating --- smtp.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/smtp.py b/smtp.py index 064f828..7d4ed8f 100644 --- a/smtp.py +++ b/smtp.py @@ -1,5 +1,6 @@ import sys import smtplib +import email.message def checkSMTPConnection(app): '''Check connection and login on SMTP server configured in app config''' @@ -21,13 +22,21 @@ def checkSMTPConnection(app): def sendMailFromHtmlForm(app, htmlForm): '''Take the app config and the contact HTML-form and send a mail accordingly''' - email = htmlForm["email"] + contact = htmlForm["email"] name = htmlForm["name"] message = htmlForm["message"] + message += "\nKontakt: " + contact subject = htmlForm["subject"] + #subject = "Subject: {} ({})\n\n".format(subject, name) + + messageBuilder = email.message.EmailMessage() + messageBuilder.set_content(message) + messageBuilder["Subject"] = subject + messageBuilder["From"] = "localhost" + messageBuilder["To"] = app.config["TARGET_EMAIL"] - subject = "Subject: {} ({})\n\n".format(subject, name) smtpTarget = smtplib.SMTP(app.config["TARGET_SMTP"]) - smtpTarget.sendmail(email, app.config["TARGET_EMAIL"] , message) + #smtpTarget.sendmail(email, app.config["TARGET_EMAIL"] , message) + smtpTarget.send_message(messageBuilder) smtpTarget.quit()