Adding mail features using Flask-Mail
Flask-Mail is an extension module that handles sending emails to an email server without too much configuration.
First, install the flask-mail module using the pip command:
pip install flask-mail
Then, create a separate module script, such as mail_config.py, to instantiate the Mail class. This approach solves the cyclic collisions that occur when views or endpoint functions access the mail instance for the utility methods.
Despite the separate module, the main.py module still needs to access the mail instance to integrate the module into the Flask platform. The following main.py snippet shows how to set up the Flask-Mail module with Flask:
from mail_config import mail
app = Flask(__name__, template_folder='pages', static_folder="resources")
app.config.from_file('config-dev.toml', toml.load)
mail.init_app(app) Afterward, the setup requires some configuration variables to be set in the config file. The...