Vipul Vipul -5 years ago 330
Python Question

smtplib of python not working

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

import smtplib

Neither this is working

import smtplib

It is giving following error:

Traceback (most recent call last):

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

Answer Source

Use port 465. From Google docs on SMTP configuration;

enter image description here

import smtplib
s = smtplib.SMTP_SSL('', 465)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download