Skip to content

Instantly share code, notes, and snippets.

@Allwin12
Created October 29, 2019 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Allwin12/00f1a4f7e0f261edd011535e7cf83b26 to your computer and use it in GitHub Desktop.
Save Allwin12/00f1a4f7e0f261edd011535e7cf83b26 to your computer and use it in GitHub Desktop.
Send email using flask and python
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