Reputation: 73
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
Upvotes: 7
Views: 23402
Reputation: 1
well i had the same problem and the way i solve it was using a VPN . cuz i noticed it was a socket problem (sock.connect(sa)) and sa means South Africa . So i simple connected my PC to an SA server and tried sending SMTP again . it worked
AppData\Local\Programs\Python\Python312\Lib\socket.py", line 837, in create_connection sock.connect(sa) TimeoutError: [WinError 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
Upvotes: 0
Reputation: 1
the reason why you were getting this error was because the password you generated for the gmail had expired in a way so just try regenerating another one using the app password in your gmail.... i tried that and it worked perfectly for mine
Upvotes: 0
Reputation: 99
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)
Upvotes: 1
Reputation: 21
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!
Upvotes: 2
Reputation: 32716
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)
Upvotes: 11