2024-08-05 08:28:09 +00:00
|
|
|
from threading import Thread
|
2024-08-05 07:59:01 +00:00
|
|
|
from flask import render_template
|
2024-08-05 05:00:07 +00:00
|
|
|
from flask_mail import Message
|
2024-08-05 07:59:01 +00:00
|
|
|
from app import mail, app
|
2024-08-05 05:00:07 +00:00
|
|
|
|
2024-08-05 08:28:09 +00:00
|
|
|
def send_async_email(app, msg):
|
|
|
|
with app.app_context():
|
|
|
|
mail.send(msg)
|
|
|
|
|
2024-08-05 05:00:07 +00:00
|
|
|
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
|
2024-08-05 14:22:32 +00:00
|
|
|
mail.send(msg)
|
|
|
|
# Thread works surprisingly badly behind uwsgi, just let a uwsgi worker do its thing instead.
|
|
|
|
#Thread(target=send_async_email, args=(app, msg)).start()
|
2024-08-05 05:00:07 +00:00
|
|
|
|
2024-08-05 07:59:01 +00:00
|
|
|
def send_password_reset_email(user):
|
|
|
|
token = user.get_reset_password_token()
|
|
|
|
hostname = app.config['REAL_HOSTNAME']
|
2024-08-08 15:14:44 +00:00
|
|
|
send_email('reset oily password',
|
2024-08-05 07:59:01 +00:00
|
|
|
sender=app.config['ADMINS'][0],
|
|
|
|
recipients=[user.email],
|
|
|
|
text_body=render_template('email/reset_password.txt', hostname=hostname, user=user, token=token),
|
|
|
|
html_body=render_template('email/reset_password.html', hostname=hostname, user=user, token=token))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|