Accessing Chat Folder in Python Using Imaplib

喜夏-厌秋 提交于 2019-12-12 16:20:15

问题


I am trying to access the Chat Folder using imaplib but am not able to do so. The code mail.select("Chats") doesn't work since "chats" is not actually a label.

How do I access the emails in the Chats folder?


回答1:


any folder you want to access by imap. it should be allowed by mail server.

e.g : for gmail, check below image for, how to set access of imap.

here, "Show in IMAP" should be checked for "Chats" folder.

then after, try below code snippets:

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

Hope, it will be helpful.



来源:https://stackoverflow.com/questions/8146970/accessing-chat-folder-in-python-using-imaplib

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!