EmailAdapter Interface¶
The EmailAdapterInterface class defines an interface to send email messages while shielding the Flask-User code from the underlying implementation.
-
class
EmailAdapterInterface
(app)¶ Define the EmailAdapter interface to send emails through various email services.
Parameters: app (Flask) – The Flask application instance. -
__init__
(app)¶ Parameters: app (Flask) – The Flask application instance.
-
send_email_message
(recipient, subject, html_message, text_message, sender_email, sender_name)¶ Send email message via an email mailer.
Parameters: - recipient – Email address or tuple of (Name, Email-address).
- subject – Subject line.
- html_message – The message body in HTML.
- text_message – The message body in plain text.
-
Tip
def __init__(self, app):
self.app = app
self.sender_name = self.app.user_manager.USER_EMAIL_SENDER_NAME
self.sender_email = self.app.user_manager.USER_EMAIL_SENDER_EMAIL
def send_email_message(...):
# use self.sender_name and self.sender_email here...
Implementing a CustomEmailAdapter¶
You can write you own EmailAdapter implementation by defining a CustomEmailAdapter class and configure Flask-User to use this class like so:
# Define a CustomEmailAdapter
from flask_user.email_adapters import EmailAdapterInterface
class CustomEmailAdapter(EmailAdapterInterface):
...
# Setup Flask-User
user_manager = UserManager(app, db, User)
# Customize Flask-User
user_manager.email_adapter = CustomDbAdapter(app)
For an example, see the SMTPEmailAdapter() implementation.