繁体   English   中英

gaierror socket.gaierror: [Errno 11001] getaddrinfo 失败 mail.send(msg)

[英]gaierror socket.gaierror: [Errno 11001] getaddrinfo failed mail.send(msg)

我正在尝试使用 flask_email 发送 email,但出现此错误:gaierror socket.gaierror: [Errno 11001] getaddrinfo failed mail.send(msg)`

from flask import Flask, render_template, request
from flask_mail import Mail, Message

app = Flask(__name__)

app.config['MAIL_SERVER']='smpt.gmail.com'
app.config['MAIL_PORT']=465
app.config['MAIL_USERNAME']= "micorreo@runchet.com"
app.config['MAIL_PASSWORD']= "miclave"
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = True

mail = Mail()

@app.route("/home", methods= ["POST", "GET"])
@app.route('/', methods= ["POST", "GET"])
def home():
    if request.method == "POST":        
        msg = Message("hi!",
                      sender="micorreo@runchet.com",
                    recipients =['testEmail@gmail.com'])
                        
        msg.body = "testing"
        mail.send(msg)
        return "send email."
    
    return render_template("index.html")

if __name__ == "__main__":
    mail.init_app(app)
    app.run(debug=True)

gaierror表示 DNS 解析错误,在您的情况下,它可能意味着主机名不存在。 我不确定这是问题所在,但我最好的猜测是这是由于第 6 行的错字造成的。您有:

app.config['MAIL_SERVER']='smpt.gmail.com'

请注意,域下不存在smpt 您指的是smtp.gmail.com吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM