email.py 932 B

12345678910111213141516171819202122232425262728293031323334353637
  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.ext.mail import Message
  11. from flaskbb.extensions import mail
  12. def send_reset_token(user, token):
  13. send_email(
  14. subject="Password Reset",
  15. recipients=[user.email],
  16. text_body=render_template(
  17. "email/reset_password.txt",
  18. user=user,
  19. token=token
  20. ),
  21. html_body=render_template(
  22. "email/reset_password.html",
  23. user=user,
  24. token=token
  25. )
  26. )
  27. def send_email(subject, recipients, text_body, html_body, sender=None):
  28. msg = Message(subject, recipients=recipients, sender=sender)
  29. msg.body = text_body
  30. msg.html = html_body
  31. mail.send(msg)