Python and MS Exchange

Mark Hammond mhammond at skippinet.com.au
Fri Feb 13 16:44:06 EST 2004


Greg Lindstrom wrote:
>>Can you tell us what object model you are using?  Provide a little 
>>sample code to give us a clue.
> 
> 
> Sure thing.
> 
> from win32all.client import Dispatch
> 
> mailbox = Dispatch("MAPI.session")
> mailbox.Login(profile='MS Exchange Settings')

OK - you are using 'simple MAPI', and this is going to be a problem for 
you down the track.  The biggest one will be the security dialog new 
versions Outlook use.

This *is* an OK way to start, but don't go too far down this track - it 
is a dead end.  On the positive side, it is possible to combine this 
'simple MAPI' with 'extended MAPI' (the latter is what SpamBayes uses)

Simple MAPI is also known as "CDO"

 > mailbox = Dispatch("MAPI.session")

Note that what you have here is a 'session' object.  Looking in the MSDN 
documentation for the CDO session object, there is no 'listfolders' method.

What you probably want is something like:
session = Dispatch("MAPI.session")
session.Logon(...)
inbox = session.Inbox
print "Inbox name is", inbox.Name
for i in range(inbox.Messages.Count):
   message = inbox.Messages.Item(i+1)
   # now 'message' has properties like 'Subject' etc

See the CDO documentation for more details.

Mark.




More information about the Python-list mailing list