[python-win32] python-win32 Digest, Vol 57, Issue 22

Tim Golden mail at timgolden.me.uk
Thu Dec 27 11:28:44 CET 2007


Antony Joseph wrote:
> Hi,
> 
> I am try to print all the message in my mailbox . its not working
> inbox = session.Inbox
> i print the value of inbox its gives <COMObject <unknown>>
> I think its not getting the inbox ?
> 
> <code>
> #
> # inbox.py
> # test case for access to Exchange; run through the
> #   hard-coded user's inbox and list the subjects of each email.
> #
> 
> import win32com.client
> session = win32com.client.gencache
>> .EnsureDispatch ("MAPI.Session")
>> session.Logon ()
>>
> inbox = session.Inbox
> 
> print  inbox
> 
> when I try to print the inbox :
> inbox = <COMObject <uknown>>
> 
> can anybody tell whats wrong in Outlook.?

I assume (from your later email) that you've realised
that nothing's wrong here. By the way, it's better to
cut-and-paste directly from your console than to
retype: it's possible that any small differences may
be vital!

By now you'll have realised that "<COMObject <unknown>>"
just means that the win32com.client libraries are doing
dynamic dispatch and so have no particular knowledge about
the COM object they're proxying, in particular its identifier.

As to your later question: how to talk directly to Exchange.
Well... there's several ways of answering this question. One
is that, although you're talking in Outlook terms in the
code above, you're not relying on Outlook as such. (There's
an alternative "Outlook.Application" dispatch-based COM object
which handles that specifically). So you *are* talking to
Exchange as directly as you can, given that it's running on
a server somewhere.

That said, though, to bypass this model altogether, you could
have Exchange expose its SMTP & IMAP interfaces and talk
that way. I believe (from rude comments elsewhere) that the MS
implementations of those protocols are less than 100%-RFC-compliant.
But it should at least be possible to get something going that
way. Obviously Python's stdlib email, smtplib and imaplib libraries
will help you out there, along with other helpers such as Menno
Smit's IMAPClient [1].

But do you have a particular reason for going that way? Rather
than simple using the MAPI.Session (aka CDO) stuff?

TJG

[1] http://freshfoo.com/wiki/CodeIndex


More information about the python-win32 mailing list