[英]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.