aboutsummaryrefslogtreecommitdiff
path: root/app/misc_func.py
diff options
context:
space:
mode:
authorNavan Chauhan <navanchauhan@gmail.com>2021-06-06 14:57:09 +0530
committerNavan Chauhan <navanchauhan@gmail.com>2021-06-06 14:57:09 +0530
commit5d2cbf0f3420a1e443b4d15e9dd938b0c1c11d68 (patch)
treef6e4ab7c685e8b40a8ce4c36b44794a793dd87f2 /app/misc_func.py
parent7d2d1b19a4699dca917add79f0a921651accbb36 (diff)
send mail with threading
Diffstat (limited to 'app/misc_func.py')
-rw-r--r--app/misc_func.py20
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