Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

socket.gaierror: [Errno 11001] getaddrinfo failed

Tags:

python

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

import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from smtplib import SMTPException


def send_Email():
    file1="abc.txt"
    message = "Test mail"
    msg = MIMEMultipart()

    msg.attach(MIMEText(file(file1).read()))

    try:
        smtpObj = smtplib.SMTP('smtp server name',port)
        smtpObj.sendmail(sender, EmailId, message, msg.as_string() )
        print "Successfully sent email"
    except SMTPException:
        print "Error: unable to send email"

Bt I have get the error: socket.gaierror: [Errno 11001] getaddrinfo failed

full error message:

 File "C:\Python27\lib\smtplib.py", line 249, in __init__
    (code, msg) = self.connect(host, port)
  File "C:\Python27\lib\smtplib.py", line 309, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "C:\Python27\lib\smtplib.py", line 284, in _get_socket
    return socket.create_connection((port, host), timeout)
  File "C:\Python27\lib\socket.py", line 553, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 11001] getaddrinfo failed
like image 962
user2499879 Avatar asked Aug 23 '13 10:08

user2499879


2 Answers

I know for sure that gaierror comes up when you are working from behind proxy.

like image 167
Deepak Saini Avatar answered Sep 21 '22 18:09

Deepak Saini


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).

like image 36
Steve Barnes Avatar answered Sep 21 '22 18:09

Steve Barnes