当我尝试使用以下设置通过Flask-Mail将电子邮件发送到Gmail的SMTP服务器时,我得到了[Errno -2] Name or service not known。如何修改我的配置以通过Gmail发送电子邮件?
[Errno -2] Name or service not known
from flask import Flask, render_template, redirect, url_for from flask_mail import Mail, Message app = Flask(__name__) app.config.update( MAIL_SERVER='smtp@gmail.com', MAIL_PORT=587, MAIL_USE_SSL=True, MAIL_USERNAME = 'ri******a@gmail.com', MAIL_PASSWORD = 'Ma*****fe' ) mail = Mail(app) @app.route('/send-mail/') def send_mail(): msg = mail.send_message( 'Send Mail tutorial!', sender='ri******a@gmail.com', recipients=['ri*********07@msn.com'], body="Congratulations you've succeeded!" ) return 'Mail sent'
MAIL_USE_TLS = True
MAIL_PORT = 587
MAIL_USE_SSL = True
MAIL_PORT = 465
MAIL_SERVER = 'smtp.gmail.com' MAIL_PORT = 465 MAIL_USE_SSL = True MAIL_USERNAME = 'username@gmail.com' MAIL_PASSWORD = 'app password generated in step 3'