Flask sends QQ email too slowly (even asynchronously). The original 150ms response page has been changed to 5s by adding email. Do you have a solution that is relatively simple ?
now I am very confused that since I have opened a new thread to send email, the view business will not wait for him to send the email but will continue to respond directly, but the actual situation is that the view business is blocked for 5s
.part of the code (written by dogs):
def send_async_email(app, msg):
with app.app_context():
mail.send(msg)
def send_email(to, subject, template, **kwargs):
app = current_app._get_current_object()
msg = Message(app.config["FLASKY_MAIL_SUBJECT_PREFIX"] + subject,
sender=app.config["FLASKY_MAIL_SENDER"], recipients=[to])
msg.body = render_template(template + ".txt", **kwargs)
msg.html = render_template(template + ".html", **kwargs)
thr = Thread(target=send_async_email, args=[app, msg])
thr.start()
return thr