3

我正在尝试使用 imaplib 访问聊天文件夹,但无法这样做。该代码mail.select("Chats")不起作用,因为“聊天”实际上不是标签。

如何访问“聊天”文件夹中的电子邮件?

4

1 回答 1

4

您想通过 imap 访问的任何文件夹。它应该被邮件服务器允许。

例如:对于 gmail,请查看下图了解如何设置 imap 的访问权限。

在此处输入图像描述

在这里,应为“聊天”文件夹检查“在 IMAP 中显示”。

然后,尝试下面的代码片段:

sock = imaplib.IMAP4_SSL("imap.gmail.com", 993)
sock.login("your Email Id", "Password")
lb_list = sock.list() # print
#search for "Chats" folder and its signature
#here, it is "[Gmail]/Chats"
sock.select("[Gmail]/Chats", True)
sock.search(None, '(ALL)')
resp, data = sock.fetch('1:*', '(RFC822)')

希望,这会有所帮助。

于 2011-11-16T08:50:18.860 回答