socket.gaierror: [Errno 11001] getaddrinfo failed

前端 未结 8 1902
北海茫月
北海茫月 2021-01-06 08:33

I have tried to attached a file to the mail using python. Code:

import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIME         


        
相关标签:
8条回答
  • 2021-01-06 08:58

    I prefer u guys to run the file as administrator for eg open cmd as administrator then type cd C:\into ur .py file path and then type python filename.py

    it worked for me. good luck

    0 讨论(0)
  • 2021-01-06 08:59

    you might did a little mistake in settings.py file.. check your code one more time in your settings file settings.py:

    EMAIL_BACKEND='django.core.mail.backends.smtp.EmailBackend'
    EMAIL_HOST = 'smtp.gmail.com'
    EMAIL_HOST_USER = 'your_email'
    EMAIL_HOST_PASSWORD = 'your_password'
    EMAIL_PORT = 587
    EMAIL_USE_TLS=True
    
    0 讨论(0)
  • 2021-01-06 09:00

    You need to login using your credential. Try:

     smtpObj = smtplib.SMTP('smtp server name',port)
    
     smtpObj .starttls() 
     smtpObj .login(email, password)
     smtpObj.sendmail(sender, EmailId, message, msg.as_string() )
     print "Successfully sent email"
    
    0 讨论(0)
  • 2021-01-06 09:03

    The problem is that the DNS lookup for 'smtp server name' is failing - if this is your exact code then you can see why - if not and you have the valid qualified name for the SMTP server then you may have issues with the firewall/internet connection, etc., also port has to be set to a valid value to match your servers SMTP configuration, (usually port 25 but not absolutely always).

    0 讨论(0)
  • 2021-01-06 09:13

    In my case was a host problem. Using debug mode, I spotted that in (host, port, 0, SOCK_STREAM) I got host=local and it should be host=localhost. In the run.py I defined localhost and the file hosts (c:\windows\system32\drivers\etc\hosts) was defined local. They have to be equal, otherwise you get the socket.gaieeror.

    0 讨论(0)
  • I know for sure that gaierror comes up when you are working from behind proxy.

    0 讨论(0)
提交回复
热议问题