0 votes
in Python Flask by
How to add the mailing feature in the Flask Application?

1 Answer

0 votes
by

To send emails, we need to install the Flask-Mail flask extension using the below-given command.

pip install Flask-Mail

Once installed, then we need to use Flask Config API to configure MAIL-SERVER, MAIL_PORT, MAIL_USERNAME, MAIL_PASSWORD, etc. Then we need to import Message Class, instantiate it and form a message object before sending the email by using the mail.send() method.

An example is shown below.

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=”[email protected]”, recipients=[“[email protected]”])

   mail.send(msg)

Related questions

0 votes
asked Dec 24, 2022 in Python Flask by sharadyadav1986
0 votes
asked Dec 23, 2022 in Python Flask by john ganales
...