Vipul
Vipul

Reputation: 576

smtplib of python not working

Trying to connect to smpt server of gmail but it is giving network unreachable

import smtplib
s=smtplib.SMTP('smtp.gmail.com',587)

Neither this is working

import smtplib
s=smtplib.SMTP_SSL('smtp.gmail.com',587)

It is giving following error:

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
  File "/usr/lib/python2.7/smtplib.py", line 311, in connect
self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib/python2.7/smtplib.py", line 286, in _get_socket
return socket.create_connection((host, port), timeout)
  File "/usr/lib/python2.7/socket.py", line 571, in create_connection
raise err
  socket.error: [Errno 101] Network is unreachable

Upvotes: 0

Views: 8156

Answers (4)

iggy12345
iggy12345

Reputation: 1393

For me, it was because the network had dissallowed opening of sockets, try a different network if possible

Upvotes: 0

Nagaraj Gaonkar
Nagaraj Gaonkar

Reputation: 11

For me when i tried in Ubuntu it is working with TLS port. Script is shown here:

import smtplib
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()

and it is working with SSL port in windows cygwin. Script is shown here:

import smtplib
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)

Upvotes: 0

Ozgur Vatansever
Ozgur Vatansever

Reputation: 52223

Use port 465. From Google docs on SMTP configuration;

enter image description here

import smtplib
s = smtplib.SMTP_SSL('smtp.gmail.com', 465)

Upvotes: 5

dg99
dg99

Reputation: 5673

According to this page port 587 requires TLS.

Upvotes: 1

Related Questions