email.py 1018 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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=""):
  28. if not sender:
  29. msg = Message(subject, recipients=recipients)
  30. else:
  31. msg = Message(subject, recipients=recipients, sender=sender)
  32. msg.body = text_body
  33. msg.html = html_body
  34. mail.send(msg)