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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With