0

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 = outlook.GetNamespace("MAPI")
for i in range(50):
    try:print(i,namespace.GetDefaultFolder(i).Name)
    except:pass

The above program revealed or created some folders that I cannot figure out how to delete, such as:

  • Reminders
  • the file so that changes to the file will be reflected in your item.
  • RSS Subscriptions

In addition to being unable to delete these folders, I still haven't actually found the folders I'm looking for programmatically. In Outlook, I have folders that I have created that are at the same level as Inbox, Sent Items, etc... but I don't know how to access the parent folder of these.

My folder structure:

  • ▼ My email address
    • Inbox
    • Drafts
    • Sent Items
    • ...
    • Folder I want to find
    • ...
    • the file so that changes to the file will be reflected in your item.
    • Reminders
    • RSS Subscriptions
    • Search Folders
ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
mbomb007
  • 3,788
  • 3
  • 39
  • 68
  • [It's unclear what specifically you need and currently have](/help/mcve). Do you need help deleting those folders, or finding some others? If the latter, which folders are you looking for? Some illustrations of your folder hierachy with pointing out the interesting parts could help explain that. – ivan_pozdeev Jun 15 '18 at 19:42
  • Both. I want to delete the folders that appeared, and I want to find the folders that, to me, appear to be in the same directory as the ones that appeared along with Inbox, Deleted Items, Sent Items, Drafts, Outbox, etc. – mbomb007 Jun 15 '18 at 20:28

2 Answers2

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 do this once per machine; after that, a regular Dispatch will do
o = win32com.client.gencache.EnsureDispatch("Outlook.Application")

from win32com.client import 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.

ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
0

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.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45