mirror of
https://github.com/FAUSheppy/flask-json-dream-website
synced 2025-12-06 08:11:35 +01:00
fix mail formating
This commit is contained in:
15
smtp.py
15
smtp.py
@@ -1,5 +1,6 @@
|
|||||||
import sys
|
import sys
|
||||||
import smtplib
|
import smtplib
|
||||||
|
import email.message
|
||||||
|
|
||||||
def checkSMTPConnection(app):
|
def checkSMTPConnection(app):
|
||||||
'''Check connection and login on SMTP server configured in app config'''
|
'''Check connection and login on SMTP server configured in app config'''
|
||||||
@@ -21,13 +22,21 @@ def checkSMTPConnection(app):
|
|||||||
def sendMailFromHtmlForm(app, htmlForm):
|
def sendMailFromHtmlForm(app, htmlForm):
|
||||||
'''Take the app config and the contact HTML-form and send a mail accordingly'''
|
'''Take the app config and the contact HTML-form and send a mail accordingly'''
|
||||||
|
|
||||||
email = htmlForm["email"]
|
contact = htmlForm["email"]
|
||||||
name = htmlForm["name"]
|
name = htmlForm["name"]
|
||||||
message = htmlForm["message"]
|
message = htmlForm["message"]
|
||||||
|
message += "\nKontakt: " + contact
|
||||||
subject = htmlForm["subject"]
|
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 = 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()
|
smtpTarget.quit()
|
||||||
|
|||||||
Reference in New Issue
Block a user