I am writing a Python program to send an email. But every time when executing the clause:
smtpserver = smtplib.SMTP(\"smtp.gmail.com\",587)
There may be some issue with the connection (maybe it is being blocked by your proxy or firewall?) and the timeout may be pretty big for you to do not see it going further.
The documentation of smtplib.SMTP says:
class smtplib.SMTP([host[, port[, local_hostname[, timeout]]]])(...) An
SMTPConnectErroris raised if the specifiedhostdoesn’t respond correctly. The optionaltimeoutparameter specifies a timeout in seconds for blocking operations like the connection attempt (if not specified, the global default timeout setting will be used).
Try specifying the timeout yourself:
smtpserver = smtplib.SMTP("smtp.gmail.com", 587, timeout=30)