Python SMTP Errno 10060
13,957
Solution 1
Try specifying a timeout (requires Python 2.6+):
smtplib.SMTP("smtp.gmail.com", 587, timeout=120)
or try connecting via SSL instead of TLS/STARTTLS (with and without timeout
):
smtplib.SMTP_SSL("smtp.gmail.com", 465)
Solution 2
I had a similar problem. The call to mailServer = smtplib.SMTP("smtp.gmail.com", 587)
just hang there, without doing anything. I can't even quit the program. It stays in the background forever!
But adding the timeout parameter solved the problem! It returns immediately and I can sent email through gmail SMTP server successfully!
Not sure why though!
Solution 3
Look my friend, see the line
mailServer = smtplib.SMTP("smtp.gmail.com", 587, timeout=120)
and put YOUR_USERNAME after the 587 number, like this
mailServer = smtplib.SMTP("smtp.gmail.com", 587, "YOUR_USERNAME", timeout=120)
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Author by
Admin
Updated on June 04, 2022Comments
-
Admin about 2 years
Can someone give me some insight as to why both this:
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
and this:
mailServer = smtplib.SMTP('smtp.gmail.com:587')
Are saying this:
Traceback (most recent call last): File "<pyshell#23>", line 1, in <module> mailServer = smtplib.SMTP("smtp.gmail.com", 587) File "C:\Users\user\Documents\Shuttlecock_new\python\lib\smtplib.py", line 242, in __init__ (code, msg) = self.connect(host, port) File "C:\Users\user\Documents\Shuttlecock_new\python\lib\smtplib.py", line 302, in connect self.sock = self._get_socket(host, port, self.timeout) File "C:\Users\user\Documents\Shuttlecock_new\python\lib\smtplib.py", line 277, in _get_socket return socket.create_connection((port, host), timeout) File "C:\Users\user\Documents\Shuttlecock_new\python\lib\socket.py", line 571, in create_connection raise err error: [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
- I'm in China.
- I have a VPN. I tried it with and without the VPN.
- I have, many times before, used this code to send e-mails from my g-mail account. Suddenly today, I got this error.
- Gmail, if accessed through my chrome browser, works fine. Albeit, it's taking an unusually long time to send simple e-mails...hmmm
-
Admin almost 13 yearsThe problem actually naturally corrected itself. Since it appears as though the problem was on gmail's end, the timeout and SSL suggestions are both very good. Thank you.