user1048962
user1048962

Reputation: 31

Accessing Chat Folder in Python Using Imaplib

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?

Upvotes: 3

Views: 907

Answers (1)

Yajushi
Yajushi

Reputation: 1185

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.

enter image description here

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.

Upvotes: 4

Related Questions