[python-win32] how to create a instance of PyIMAPISession by hand

2013-05-08 Thread Christian K .

The following code has been suggested to me to get a handle to Outlook's
mapi session.


from win32com.client import Dispatch
from win32com.mapi import mapi
app = Dispatch('Outlook.Application')
app.GetNamespace('MAPI').Session.MAPIOBJECT

The MAPIOBJECT would then have to be cast to a IMAPISession object. How
would I do that? By calling the PyIMAPISesison constructor with MAPIOBJECT
as argument? Unfortunately I was not able to find the PyIMAPISession class
in the pywin32 namespace nor when digging through the source.



Any hints are very much appreciated.

Christian

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] how to create a instance of PyIMAPISession by hand

2013-05-08 Thread Mark Hammond

On 8/05/2013 11:29 PM, Christian K. wrote:


The following code has been suggested to me to get a handle to Outlook's
mapi session.


from win32com.client import Dispatch
from win32com.mapi import mapi
app = Dispatch('Outlook.Application')
app.GetNamespace('MAPI').Session.MAPIOBJECT

The MAPIOBJECT would then have to be cast to a IMAPISession object. How
would I do that? By calling the PyIMAPISesison constructor with MAPIOBJECT
as argument? Unfortunately I was not able to find the PyIMAPISession class
in the pywin32 namespace nor when digging through the source.




It should be something like:

from win32com.mapi import mapi
session = 
app.GetNamespace('MAPI').Session.MAPIOBJECT.QueryInterface(mapi.IID_IMAPISession)


Note that a good resource for working with MAPI from pywin32 is the 
spambayes project, and particularly:


https://github.com/smontanaro/spambayes/blob/master/spambayes/Outlook2000/msgstore.py

For reasons that escape me now, it does things differently - after 
creating the Outlook.app object, it does:


mapi.MAPIInitialize(None)
logonFlags = (mapi.MAPI_NO_MAIL |
  mapi.MAPI_EXTENDED |
  mapi.MAPI_USE_DEFAULT)
self.session = mapi.MAPILogonEx(0, None, None, logonFlags)

to get the session.  Note however that that code was written against 
Office 2000, so some things - especially work-arounds etc - may well 
have changed


HTH,

Mark

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32