Skip to content Skip to sidebar Skip to footer

How To Get A Specific Folder With Getdefaultfolder And Delete Unneeded Folders That It Has Created

I was trying to figure out how to access my folders with a Python program (see this SO answer.) When I ran this: outlook = win32com.client.Dispatch('Outlook.Application') namespace

Solution 1:

GetDefaultFolder's argument is a enumeration. You can either use a numeric value that's courteously given in the doc,

or, as per Accessing enumaration constants in Excel COM using Python and win32com , access it via the symbolic value:

#need to only dothis once per machine; after that, a regular Dispatch will do
o = win32com.client.gencache.EnsureDispatch("Outlook.Application")

from win32com.clientimport constants
o.GetDefaultFolder(constants.olFolderContacts)

As you could see, accessing a default folder that didn't yet exist creates it. See e.g. How to Hide or Delete Outlook's Default Folders on how to deal with them.

Solution 2:

You need to specify a value from the OlDefaultFolders enumeration without iterating over all possible values for the GetDefaultFolder method.

You can't delete IPM folders like Inbox, Outbox and etc. using the Outlook object model.

Post a Comment for "How To Get A Specific Folder With Getdefaultfolder And Delete Unneeded Folders That It Has Created"