python - 从 imap 或 pop3 服务器读取电子邮件

标签 python python-2.7 imap pop3 imaplib

我的任务是使用 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 帮助页面

https://support.google.com/mail/accounts/answer/7875

关于python - 从 imap 或 pop3 服务器读取电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43631176/

相关文章:

Python lxml 防止小于 < 或大于 > 被转换为 &lt 和 &gt

Python 需要请求 GitHub/API/repo/statistics/contributors url 两次才能获取内容

amazon-web-services - 在 amazon ec2 linux 2 上安装 php-imap

python - 使用 Python 的 Gmail 中的 IMAP 问题

java - Java 中的 IMAP 客户端 : JavaMail API or Apache Commons Net?

python - 是否有现有的库或脚本集可以用 Python 为 Google Calendar API 编写重复事件字符串?

python - Firefox 断开连接后 Flask sse-stream 未终止

python - 编写您的第一个 Django 应用程序时,出现 from 错误。导入 View

python - 实现特定的比较功能

python - 如何使用请求模块将数据发布到 flask 应用程序?