diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/misc_func.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/app/misc_func.py b/app/misc_func.py index 11e2bb2..73e920d 100644 --- a/app/misc_func.py +++ b/app/misc_func.py @@ -1,4 +1,7 @@ +from threading import Thread from flask import flash +from flask_mailman import EmailMultiAlternatives +from app import app, mail def flash_errors(form): for field, errors in form.errors.items(): @@ -6,4 +9,19 @@ def flash_errors(form): flash(u"Error in the %s field - %s" % ( getattr(form, field).label.text, error - ), 'danger')
\ No newline at end of file + ), 'danger') + +# Sauce: https://github.com/alectrocute/flaskSaaS/blob/master/app/toolbox/email.py + +def send(to, subject, body, body_html,thread=True): + sender = app.config["MAIL_FROM"] + message = EmailMultiAlternatives( + subject,body,sender,[to]) + message.attach_alternative(body_html,"text/html") + thr = Thread(target=send_async, args=[app,message]) + thr.start() + +def send_async(app, message): + with app.app_context(): + message.send() + print("Mail Sent")
\ No newline at end of file |