[python-win32] getting global addressbook with extended mapi
Filip Van Raemdonck
mechanix at debian.org
Mon Jan 9 16:52:47 CET 2006
Hi,
Looking around to (ab)use the Exchange GAL from python I found the code
snippet listed below, posted to this list last summer.
When I try it, I get an exception in the fourth last statement:
<traceback>
...
rows = mapi.HrQueryAllRows(...)
com_error: (-2147220992, 'CONNECT_E_NOCONNECTION', None, None)
</traceback>
Does anyone have an idea why the connection could have gone lost at that
point? Or am I misinterpreting the error?
On Thu, Jun 09, 2005 at 05:39:56AM +0200, python at kareta.de wrote:
>
> 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>
Regards,
Filip
--
"I decry the current tendency to seek patents on algorithms. There are
better ways to earn a living than to prevent other people from making
use of one's contributions to computer science."
-- D.E. Knuth, TAoCP 3
More information about the Python-win32
mailing list