Outlook using python win32com to iterate subfolders

Yeah its better to write it as the name of the folder instead of writing the folder numbers

Like my folder hierarchy is : Outlook_Mails > Inbox > Important

outlook = win32.com.client.Dispatch("Outlook.Application")
mapi = outlook.GetNamespace("MAPI")

your_folder = mapi.Folders['Outlook_Mails'].Folders['Inbox'].Folders['Important']
for message in your_folder.Items:
    print(message.Subject)

Can't do that - Outlook caches shared default folders in the main OST file The subfolders are not cached. If the mailbox in question is added as a delegate store, you should be able to parse to the folder in question using Namespace.Folders or Namespace.Stores.

Otherwise you can use Redemption (I am its author) and its RDOSession.GetSharedDefaultFolder - the folder will be opened in the online mode with all of its subfolders (RDOFolder.Folders).


This is the code I'm using to do a similar task.

outlook = win32com.client.Dispatch("Outlook.Application")
namespace = outlook.GetNamespace("MAPI")
root_folder = namespace.Folders.Item(1)
subfolder = root_folder.Folders['All'].Folders['Main Folder'].Folders['Subfolder']
messages = subfolder.Items

This finds the messages in the folder "All/Main Folder/Subfolder".