10

This is how I am able to access the inbox:

   outlook = Dispatch("Outlook.Application").GetNamespace("MAPI")
   inbox = outlook.GetDefaultFolder("6")

When I tried to access the user created folders in Outlook using the below code:

   outlook = Dispatch("Outlook.Application").GetNamespace("MAPI")
   Folder = outlook.Folders[1]
   print (Folder)

I got this error:

  raise IndexError("list index out of range")

IndexError: list index out of range

Any help would be appreciated.

soldy
  • 103
  • 1
  • 1
  • 5

1 Answers1

22

Globally, you can do:

from win32com.client import Dispatch
outlook = Dispatch("Outlook.Application").GetNamespace("MAPI")
root_folder = outlook.Folders.Item(1)

Then you can check the name of this folder by

print (root_folder.Name)

And to know the names of the subfolders you have:

for folder in root_folder.Folders:
    print (folder.Name)

Finally, let's say you want to access a subfolder named folder_of_soldy in your root_folder, you do:

soldy_folder = root_folder.Folders['folder_of_soldy']

And so on if you have other subfolders in folder_of_soldy.

Hope you find what you need

Ben.T
  • 29,160
  • 6
  • 32
  • 54