[python-win32] List of keys and values

Tim Golden mail at timgolden.me.uk
Wed Feb 19 10:18:50 CET 2014


On 18/02/2014 18:59, Aaron Reabow wrote:
> Hi Guys,
> 
> This should be dead simple.
> 
> I am just trying to find a list of all of the key value pairs held for
> each message.
> 
> 
> These are the ones that I have found so far:
> 
>   * subject
>   * SenderName
>   * Recipients
>   * TaskDueDate
> 
> I am using this simple code snippet
> 
> import win32com.client
> 
> outlook =
> win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
> 
> inbox = outlook.GetDefaultFolder(6) # "6" refers to the index of a
> folder - in this case,
>                                     # the inbox. You can change that
> number to reference
>                                     # any other folder
> messages = inbox.Items
> message = messages.GetLast()
> 
> then doing this for eample:
> 
> 
> for message in messages:
>     print message.TaskDueDate
> 
> 
> i was wondering what else I can get access to for a message?

First of all, thanks for giving a self-contained code example so we know
what you're seeing. Next, by way of answering your question somewhat
indirectly, try this:

<code>
import win32com.client

app = win32com.client.gencache.EnsureDispatch("Outlook.Application")
outlook = app.GetNamespace("MAPI")

print(repr(outlook))
help(outlook)

</code>

Because I've generated a static proxy for the underlying COM objects,
you can use the standard Python introspection for a certain amount of
useful information. Generally you can see the methods with their parameters.

Also, though, instead of a generic "<COM Object>" you can see that the
"outlook" object is an instance of the _Namespace class in the Outlook
12.0 object library. Even if there was nothing else you could do through
Python itself, you can drop those terms into a search engine and come up
with something like:

  http://msdn.microsoft.com/en-us/library/office/bb219955.aspx

Obviously you can do the same with the messages etc. so:

<code>
# carrying on from above...

inbox = outlook.GetDefaultFolder(6)
message = inbox.Items.GetLast()

print(repr(message))
help(message)

</code>

and here, the message is a MailItem instance and so we can get to here:

  http://msdn.microsoft.com/en-us/library/office/ff861252.aspx

and so on.

If you want to, you can go digging in the _prop_map_get_ attribute which
is how the Python Dispatch wrapper stores its internal mappings, but
it's a little involved if you're just hoping for a list of attribute
names (and, especially, their meanings).

TJG


More information about the python-win32 mailing list