简体   繁体   中英

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

I'm trying to send email with flask_email and I get this error: 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 means DNS resolution error, and in your case it probably means that the hostname does not exist. I'm not sure this is the problem, but my best guess is that this is due to a typo on line 6. You have:

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

Notice that smpt does not exist under the domain. Did you mean smtp.gmail.com ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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