[英]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.