Reputation: 48
I am trying to send an email using Flask-mail
but for some reason it always give me this error
ConnectionResetError: [WinError 10054]
By the way, I already configured my Gmail account to allow low security applications.
Here is the code:
from flask import Flask
from flask_mail import Mail, Message
app =Flask(__name__)
app.config['MAIL_SERVER']='smtp.gmail.com'
app.config['MAIL_PORT'] = 587
app.config['MAIL_USERNAME'] = 'sender.gmail'
app.config['MAIL_PASSWORD'] = 'sender.password'
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = True
mail = Mail(app)
@app.route("/")
def index():
msg = Message('Hello', sender = 'sender.gmail', recipients = ['reciever.gmail'])
msg.body = "Hello there!"
mail.send(msg)
if __name__ == '__main__':
app.run(debug=True)
Upvotes: 0
Views: 300
Reputation: 182
The configuration seems confusing. When you set the username and the password as something like 'sender.gmail' and 'sender.password' which is string (It's not going to be changed anywhere else in your code), certainly, that user wont be recognized by smtp.gmail.com .
Use something real, like [email protected]
and sup3rp4ssw0rd
.
flask_mail documentation.
Upvotes: 1