3
pwd = "mypassword"
import smtplib

server = smtplib.SMTP('smtp.gmail.com')
server.ehlo()
server.starttls()
server.login("[email protected]",pwd)

msg = "YOUR MESSAGE!"
server.sendmail("[email protected]", "[email protected]", msg)
server.quit()

I have tried sending a mail through python...
Error :

Traceback (most recent call last):
  File "H:/my projects/PythonCourse/test_cont/mail_test4.py", line 4, in <module>
    server = smtplib.SMTP('smtp.gmail.com')
  File "C:\Python27\lib\smtplib.py", line 256, in __init__
    (code, msg) = self.connect(host, port)
  File "C:\Python27\lib\smtplib.py", line 316, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "C:\Python27\lib\smtplib.py", line 291, in _get_socket
    return socket.create_connection((host, port), timeout)
  File "C:\Python27\lib\socket.py", line 557, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 11001] getaddrinfo failed

I am connecting through a proxy connection
I set the proxy through cmd in windows. Please help me with this.

Update :
I am sure with the internet connection :

import urllib2

def internet_on():
    try:
        response=urllib2.urlopen('https://www.google.co.in',timeout=1)
        return True
    except urllib2.URLError as err: pass
    return False

print internet_on()

Output is True

4
  • 1
    is it working without proxy ? Maybe problem is your proxy, not Python code. Commented Feb 12, 2016 at 12:05
  • Look like you don't have proper DNS resolution, wich is not uncommon for proxied networks. Unluckily we can not give advise since a) we don't know anything about your network and b) network configuration issues are out of the scope of SO. Commented Feb 12, 2016 at 12:07
  • Please have a look at the update Commented Feb 12, 2016 at 12:11
  • smtp.gmail.com must be accessed on port 465 (SSL required) or port 587 (TLS required) docs Commented Feb 12, 2016 at 12:24

2 Answers 2

7

Your code works fine for me, so it's probably the connection settings.

Try changing server to:

server = smtplib.SMTP('64.233.184.108')

(that's the IP address of smtp.gmail.com, to bypass DNS resolution)

Sign up to request clarification or add additional context in comments.

Comments

0

Try updating the

server = smtplib.SMTP('smtp.gmail.com')
to include a port. The port for gmail is 587, so add that as a second parameter:
server = smtplib.SMTP('smtp.gmail.com', 587)

If this does not work, make sure that you have used this site to make sure that the account will let you in:

https://www.google.com/settings/security/lesssecureapps

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.