[python-win32] Accessing non-default folders in Outlook 2010?

Anders Schneiderman aschneiderman at gmail.com
Thu Aug 25 11:47:00 CEST 2011


When I tried it:
folders = outlook.GetRootFolder()

I got the following error message:
AttributeError: object has no attribute 'GetRootFolder


FYI, when I do:
print dir(outlook)

that method doesn't show up:
['AddStore', 'AddStoreEx', 'CLSID', 'CompareEntryIDs', 'CreateContactCard',
'CreateRecipient', 'CreateSharingItem', 'Dial', 'GetAddressEntryFromID',
'GetDefaultFolder', 'GetFolderFromID', 'GetGlobalAddressList',
'GetItemFromID', 'GetRecipientFromID', 'GetSelectNamesDialog',
'GetSharedDefaultFolder', 'GetStoreFromID', 'Logoff', 'Logon',
'OpenSharedFolder', 'OpenSharedItem', 'PickFolder', 'RefreshRemoteHeaders',
'RemoveStore', 'SendAndReceive', '_ApplyTypes_', '__cmp__', '__doc__',
'__getattr__', '__init__', '__module__', '__repr__', '__setattr__',
'_get_good_object_', '_get_good_single_object_', '_oleobj_',
'_prop_map_get_', '_prop_map_put_', 'coclass_clsid']

dir doesn't always pick everything up, but just in case it's useful...

Full code below:
----------------------------------
import win32com.client

# Connect to Outlook, which has to be running
try:
    print "trying to open up Outlook..."
    outlook =
win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
except:
    print "Could not open Outlook"
print "successfully connected to Outlook\n"

# Count the number of messages in the inbox
inbox = outlook.GetDefaultFolder(win32com.client.constants.olFolderInbox)
messages = inbox.Items
print "number of messages in inbox:", messages.Count

# Count the number of tasks in the task list
task_list =
outlook.GetDefaultFolder(win32com.client.constants.olFolderTasks)
tasks = task_list.Items
print "number of tasks in the task list:", tasks.Count


folders = outlook.GetRootFolder()

----------------------------------
Thanks,
Anders



On Wed, Aug 24, 2011 at 6:37 PM, Tim Roberts <timr at probo.com> wrote:

> Anders Schneiderman wrote:
> >
> > I'm trying to read messages that are in folders in Outlook 2010, and
> > I'm running into trouble. Between looking at other folk's code and
> > trying to make sense out of the Microsoft Object Model documentation,
> > I've been able to figure out how to read items in the inbox and other
> > things in default folders, such as tasks:    by using GetDefaultFolder.
> >
>
> I think you want outlook.GetRootFolder(), then enumerate the Folders
> collection within that.
>
> http://msdn.microsoft.com/en-us/library/ff860733.aspx
>
> --
> Tim Roberts, timr at probo.com
> Providenza & Boekelheide, Inc.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20110825/dee19228/attachment-0001.html>


More information about the python-win32 mailing list