email.py 976 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. # -*- coding: utf-8 -*-
  2. """
  3. flaskbb.emails
  4. ~~~~~~~~~~~~~~~~~~~~
  5. This module adds the functionality to send emails
  6. :copyright: (c) 2014 by the FlaskBB Team.
  7. :license: BSD, see LICENSE for more details.
  8. """
  9. from flask import render_template
  10. from flask_mail import Message
  11. from flask_babelex import lazy_gettext as _
  12. from flaskbb.extensions import mail
  13. def send_reset_token(user, token):
  14. send_email(
  15. subject=_("Password Reset"),
  16. recipients=[user.email],
  17. text_body=render_template(
  18. "email/reset_password.txt",
  19. user=user,
  20. token=token
  21. ),
  22. html_body=render_template(
  23. "email/reset_password.html",
  24. user=user,
  25. token=token
  26. )
  27. )
  28. def send_email(subject, recipients, text_body, html_body, sender=None):
  29. msg = Message(subject, recipients=recipients, sender=sender)
  30. msg.body = text_body
  31. msg.html = html_body
  32. mail.send(msg)