[python-win32] getting global addressbook with extended mapi
python@kareta.de
python at kareta.de
Thu Jun 9 05:39:56 CEST 2005
Hi all,
Mark wrote:
>Why? Is something missing, or it just tricky?
>
>Sadly, if you want easy, you use CDO/Simple MAPI. Extended MAPI is not for
>the faint hearted (or for people with deadlines :)
I think, that's not a matter of to be clench or not. Diving into a crazy
organized library with poor and peripheral dokumentation is just waste of time.
But anyway, if there are more faint hearted outside, here is the code working
for me:
<code>
from win32com.mapi.mapitags import *
from win32com.mapi import mapi
from win32com.mapi import mapiutil
profileName = "Test"
session = mapi.MAPIInitialize(None)
session =mapi.MAPILogonEx(0,profileName,None, mapi.MAPI_EXTENDED |
mapi.MAPI_LOGON_UI |\
mapi.MAPI_NO_MAIL |mapi.MAPI_USE_DEFAULT)
hr=session.OpenAddressBook(0,None,mapi.AB_NO_DIALOG)
##open rootcontainer
root=hr.OpenEntry(None,None,mapi.MAPI_BEST_ACCESS)
##get items
root_htab=root.GetHierarchyTable(0)
##restrict for GAL
##SPropValue should be 'DT_GLOBAL' but not defined in mapitags
DT_GLOBAL=131072
restriction = (mapi.RES_PROPERTY,
(1,
PR_DISPLAY_TYPE,
(PR_DISPLAY_TYPE, DT_GLOBAL)))
## get GAL's entryid tuple
gal_id = mapi.HrQueryAllRows(root_htab,
(PR_ENTRYID),
restriction,
None,
0)
## extract GAL's entryid
gal_id = gal_id[0][0][1]
## open GAL
gal=hr.OpenEntry(gal_id,None,mapi.MAPI_BEST_ACCESS)
## get content
gal_list=gal.GetContentsTable(0)
## no readable tagname for smpt
PR_SMTP=972947486
rows = mapi.HrQueryAllRows(gal_list,
(PR_ENTRYID,
PR_DISPLAY_NAME_A,PR_ACCOUNT,PR_SMTP),
None,
None,
0)
for eid,name,alias,smtp in rows:
print name[1],alias[1],smtp[1]
mapi.MAPIUninitialize()
</code>
PS.: Expanding a distribution lists of the GAL needs to set the address type of
that dl to 'MAPIPDL', but I'm lacking the permissions - crazy, crazy
regards,
Jürgen
-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/
More information about the Python-win32
mailing list