When I try to send an email using Flask-Mail to Gmail's SMTP server using the settings below, I get [Errno -2] Name or service not known
. How do I fix my configuration to send email with Gmail?
from flask import Flask, render_template, redirect, url_for
from flask_mail import Mail, Message
app = Flask(__name__)
app.config.update(
MAIL_SERVER='[email protected]',
MAIL_PORT=587,
MAIL_USE_SSL=True,
MAIL_USERNAME = 'ri******[email protected]',
MAIL_PASSWORD = 'Ma*****fe'
)
mail = Mail(app)
@app.route('/send-mail/')
def send_mail():
msg = mail.send_message(
'Send Mail tutorial!',
sender='ri******[email protected]',
recipients=['ri*********[email protected]'],
body="Congratulations you've succeeded!"
)
return 'Mail sent'
MAIL_USE_TLS = True
, then use MAIL_PORT = 587
.MAIL_USE_SSL = True
, then use MAIL_PORT = 465
.MAIL_SERVER = 'smtp.gmail.com'
MAIL_PORT = 465
MAIL_USE_SSL = True
MAIL_USERNAME = '[email protected]'
MAIL_PASSWORD = 'app password generated in step 3'