Created
October 29, 2019 12:28
-
-
Save Allwin12/00f1a4f7e0f261edd011535e7cf83b26 to your computer and use it in GitHub Desktop.
Send email using flask and python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
from flask_mail import Mail, Message | |
app = Flask(__name__) | |
mail = Mail(app) | |
app.config['MAIL_SERVER'] = 'smtp.gmail.com' | |
app.config['MAIL_PORT'] = 465 | |
app.config['MAIL_USERNAME'] = 'yourmail@mail.com' | |
app.config['MAIL_PASSWORD'] = 'yourpassword' | |
app.config['MAIL_USE_TLS'] = False | |
app.config['MAIL_USE_SSL'] = True | |
mail = Mail(app) | |
@app.route("/") | |
def index(): | |
msg = Message('Hello', sender='yourmail@mail.com', recipients=['allwindicaprio@gmail.com']) | |
msg.body = "Hello Flask message sent from Flask-Mail" | |
mail.send(msg) | |
return "Sent" | |
if __name__ == '__main__': | |
app.run(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment