无法在python中使用IMAP连接到gmail/Outlook

无法在python中使用IMAP连接到gmail/Outlook,python,imap,chilkat-email,Python,Imap,Chilkat Email,我曾尝试使用Chilkat包在Spyder(Python3.6)中使用IMAP连接到Gmail服务器。 我已经在设置>转发和POP/IMAP中为所有邮件启用了IMAP,并且在登录后,我还在此处启用了不太安全的应用程序选项卡。但是在这个代码中 import sys import chilkat imap = chilkat.CkImap() # Anything unlocks the component and begins a fully-functional 30-day trial.

我曾尝试使用Chilkat包在Spyder(Python3.6)中使用IMAP连接到Gmail服务器。 我已经在设置>转发和POP/IMAP中为所有邮件启用了IMAP,并且在登录后,我还在此处启用了不太安全的应用程序选项卡。但是在这个代码中

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()

#  Connect to an IMAP server.
#  Use TLS
imap.put_Ssl(True)
imap.put_Port(993)
success = imap.Connect("imap.gmail.com")

success
变量是
布尔值
仍然为False。请帮帮我。我的目标是从Outlook Server获取所有附件并将它们转储到一个文件中。但我甚至无法连接到Gmail服务器。我尝试使用“imap.mail.Outlook.com”,但也失败了。我不知道在Outlook中启用IMAP的步骤。但是,即使它在Gmail中被启用,为什么它不工作呢?

第一步是检查imap.LastErrorText属性的内容,看看发生了什么。例如:

#  Connect to an IMAP server.
#  Use TLS
imap.put_Ssl(True)
imap.put_Port(993)
success = imap.Connect("imap.someMailServer.com")
if (success != True):
    print(imap.lastErrorText())
    sys.exit()
我的猜测是防火墙(软件或硬件)正在阻止出站连接


另一种解决方案是使用GMail REST API,如以下示例所示:HTTP端口(443)不太可能被防火墙阻止。您将下载到Chilkat电子邮件对象中,然后以与通过IMAP下载完全相同的方式保存附件。

我认为出现此问题的原因是,尽管您进行了更改,但无法与IMAP服务器建立连接。您是否使用telnet或socat或类似工具验证了您的主机可以访问IMAP.gmail.com的IMAP港口城市默认情况下,它在许多防火墙上被阻止。