Created
January 1, 2020 05:16
-
-
Save ethanpost/2c4970792006ff7365d89ba77afe456c to your computer and use it in GitHub Desktop.
Example of using Flask-Mail with Gmail
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
# This code works for me :) | |
from flask import Flask | |
from flask_mail import Mail, Message | |
app = Flask(__name__) | |
app.config.update(dict( | |
DEBUG=True, | |
MAIL_SERVER='smtp.gmail.com', | |
MAIL_PORT=587, | |
MAIL_USE_TLS=True, | |
MAIL_USE_SSL=False, | |
MAIL_USERNAME='post.ethan@gmail.com', | |
# Use google account to generate a custom password here. This is not your "normal" pass. | |
MAIL_PASSWORD='fhrkfhrfhrkfhkrhfkr', | |
)) | |
mail = Mail(app) | |
m = Message("Hello", sender="post.ethan@gmail.com", recipients=["post.ethan@gmail.com"]) | |
m.body = "Testing" | |
m.html = "<i>Testing</i>" | |
def send_email(mail_message): | |
with app.app_context(): | |
mail.send(mail_message) | |
send_email(m) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment