socket.error:使用Python发送电子邮件时,[Errno 10060]

时间:2018-09-19 01:23:04

标签: python

我正在学习Python,并想尝试一个小的python脚本,我可以在其中使用该脚本发送电子邮件。

我的代码:

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


server.login("youremailusername", "password")


msg = "Hello! Test Script For Sending an email" 

server.sendmail("you@gmail.com", "target@example.com", msg)

错误消息:

socket.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

有人可以帮我解决问题吗?

1 个答案:

答案 0 :(得分:0)

您所在的网络可能正在阻止该端口(587)进行传出连接,或者Google可能正在阻止您的IP地址。如果您使用的是VPS,则可以检查系统的防火墙设置,并查看是否可以打开它。