繁体   English   中英

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

[英]Unable to connect to gmail/Outlook using IMAP in python

我尝试使用Chilkat软件包在Spyder(Python 3.6)中使用IMAP连接到Gmail服务器。 登录后,我已在“ 设置”>“转发”和POP / IMAP中为所有邮件启用了IMAP,然后在https://myaccount.google.com/lesssecureapps?pli=1处启用了安全性较低的应用程序标签 。但是在此代码

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

boolean 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,如以下示例所示: https : //www.example-code.com/python/gmail.asp HTTP端口(443)不太可能被防火墙阻止。 您将下载到Chilkat电子邮件对象中,然后以与通过IMAP下载时完全相同的方式保存附件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM