我的任务是使用 imap 或 pop3 服务器地址读取电子邮件。我正在尝试使用 python 来完成这个任务。所有可用于执行此任务的示例代码都会引发下面提到的错误
“错误:[Errno 10060] 连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机未能响应”
问题可能是什么,是我的本地防火墙设置还是由于其他原因......???
import imaplib
imap_host = 'imap.gmail.com'
imap_user = '****@gmail.com'
imap_pass = '****'
## open a connection
imap = imaplib.IMAP4_SSL(imap_host)
## login
imap.login(imap_user, imap_pass)
和
import sys
import chilkat
imap = chilkat.CkImap()
# Anything unlocks the component and begins a fully-functional 30-day trial.
success = imap.UnlockComponent("Anything for 30-day trial")
if (success != True):
print(imap.lastErrorText())
sys.exit()
# Turn on session logging:
imap.put_KeepSessionLog(True)
# Connect to GMail
# Use TLS
imap.put_Ssl(True)
imap.put_Port(993)
success = imap.Connect("imap.gmail.com")
if (success != True):
print(imap.lastErrorText())
sys.exit()
# Login
# Your login is typically your GMail email address.
success = imap.Login("***@gmail.com","*****")
if (success != True):
print(imap.lastErrorText())
sys.exit()
# Select an IMAP mailbox
success = imap.SelectMailbox("Inbox")
if (success != True):
print(imap.lastErrorText())
sys.exit()
# Show the session log.
print(imap.sessionLog())
# Disconnect from the IMAP server.
success = imap.Disconnect()
最佳答案
首先,我建议进行一个简单的网络健全性测试,例如:使用 Telnet,如下所示:
telnet imap.gmail.com 993
如果网络正常,您应该会看到如下响应:
Trying 64.233.188.109...
Connected to gmail-imap.l.google.com.
Escape character is '^]'.
也可能值得查看 IMAP 的 Gmail 帮助页面
关于python - 从 imap 或 pop3 服务器读取电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43631176/