rdm_
rdm_

Reputation: 67

Python exchangelib read mails in subfolder

I want to read the mails from the subfolder of the outlook mailbox.

Inbox
├──myfolder

I can read Inbox using account.inbox.all() but i want to read mails in myfolder

I tried the things in folder section of this page but i couldn't get it right

https://pypi.python.org/pypi/exchangelib/

Upvotes: 3

Views: 4383

Answers (2)

AgentLog
AgentLog

Reputation: 107

Just in case if you have a lot of sub-folders (including nested ones) inside your directory and you want to print the subject of all then use this method.

folder = account.root/'Top of Information Store'/'Inbox'/folder_name
all_folders = folder.glob('**/*')
for subfolders in all_folders:
    for emails in subfolders.all():
        print(emails.subject)

Upvotes: 0

Erik Cederstrand
Erik Cederstrand

Reputation: 10220

You need to get hold of the Folder instance for myfolder first:

my_folder = account.inbox / 'myfolder'
for i in my_folder.all():
    print(i.subject)

Upvotes: 4

Related Questions