aboutsummaryrefslogtreecommitdiff
path: root/app/email.py
diff options
context:
space:
mode:
authorGertjan van den Burg <gertjanvandenburg@gmail.com>2019-03-18 16:05:36 +0000
committerGertjan van den Burg <gertjanvandenburg@gmail.com>2019-03-18 16:05:36 +0000
commitb499f31dfcb4e3cf27c34ae0958612a9d43bf910 (patch)
tree71e19ad212225060c1ccd3bd9308e0420b1f3ad8 /app/email.py
parentadd gitignore (diff)
downloadAnnotateChange-b499f31dfcb4e3cf27c34ae0958612a9d43bf910.tar.gz
AnnotateChange-b499f31dfcb4e3cf27c34ae0958612a9d43bf910.zip
add errors, email, and reset password
Diffstat (limited to 'app/email.py')
-rw-r--r--app/email.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/app/email.py b/app/email.py
new file mode 100644
index 0000000..8c71a50
--- /dev/null
+++ b/app/email.py
@@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+
+from threading import Thread
+
+from flask import render_template
+from flask_mail import Message
+
+from app import app
+from app import mail
+
+
+def send_async_email(app, msg):
+ with app.app_context():
+ mail.send(msg)
+
+
+def send_email(subject, sender, recipients, text_body, html_body):
+ msg = Message(subject, sender=sender, recipients=recipients)
+ msg.body = text_body
+ msg.html = html_body
+ Thread(target=send_async_email, args=(app, msg)).start()
+
+
+def send_password_reset_email(user):
+ token = user.get_reset_password_token()
+ send_email(
+ "[AnnotateChange] Reset your password",
+ sender=app.config["ADMINS"][0],
+ recipients=[user.email],
+ text_body=render_template(
+ "email/reset_password.txt", user=user, token=token
+ ),
+ html_body=render_template(
+ "email/reset_password.html", user=user, token=token
+ ),
+ )