To send emails, run the following command to install the Flask-Mail flask extension: pip install Flask-Mail Next, we'll need to configure the Flask Config API to set up MAIL_SERVER, MAIL_PORT, MAIL_USERNAME, MAIL_PASSWORD, and so on. Then we must import the Message Class, instantiate it, and create a message object before using the mail.send() function to send the email. The following is an example: from flask_mail import Mail, Message
from flask import Flask
app = Flask(__name__)
mail = Mail(app)
@app.route("/mail")
def email():
msg = Message( "Hello Message", sender="admin@test.com", recipients=["to@test.com"])
mail.send(msg)