From e903c4092fdd0cbfe4e2829427dd291d68499e29 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Wed, 22 Apr 2020 16:43:51 +0100 Subject: [PATCH] Add the ability to mail admin. --- depicts/mail.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 depicts/mail.py diff --git a/depicts/mail.py b/depicts/mail.py new file mode 100644 index 0000000..1f2771f --- /dev/null +++ b/depicts/mail.py @@ -0,0 +1,20 @@ +from flask import current_app +from email.mime.text import MIMEText +from email.utils import formatdate, make_msgid +import smtplib + +def send_mail(subject, body): + app = current_app + mail_to = app.config['ADMIN_EMAIL'] + mail_from = app.config['MAIL_FROM'] + msg = MIMEText(body, 'plain', 'UTF-8') + + msg['Subject'] = subject + msg['To'] = mail_to + msg['From'] = mail_from + msg['Date'] = formatdate() + msg['Message-ID'] = make_msgid() + + s = smtplib.SMTP(app.config['SMTP_HOST']) + s.sendmail(mail_from, [mail_to], msg.as_string()) + s.quit()