querying microsoft outlook global address list
Jason Betts <[email protected]> Tue, 12 Jul 2005 08:54:53 -0500
| Newsgroups | gmane.comp.windows.devel.jawin |
|---|---|
| Message-ID | <[email protected]> |
Hi all,
I'm working on using jawin to query outlook's GAL. I've got it so that I
can obtain the address entries of the GAL, however I can't seem to access
the *Filter property of the address entries( *
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdo/html/_olemsg_filter_property_addressentries_collection_.asp)
or the Fields property of an address entry (
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdo/html/_olemsg_fields_property_addressentry.asp
).
My overall objective is to be able to query the GAL with some of the fields
stored in the address book. Here is my code snipet:
try{
Ole32.CoInitialize();
String nombre,direccion,to,subject,body;
int i=0;
System.out.println("Before calling Outlook");
DispatchPtr app = new DispatchPtr("Outlook.Application");
System.out.println("After calling Outlook");
//app.put("Visible", -1);
//System.out.println("Propiedad visible");
DispatchPtr namespace=(DispatchPtr)app.invoke("GetNameSpace","MAPI");
System.out.println("MAPI Namespace");
DispatchPtr addressLists=(DispatchPtr)namespace.get("AddressLists");
// DispatchPtr addressBook=(DispatchPtr)namespace.invoke("AddressBook");
System.out.println("After Address Book");
Integer countAddressLists=(Integer)addressLists.get("Count");
int countAddressListsInt=countAddressLists.intValue();
System.out.println("There are " + countAddressListsInt + " address lists");
DispatchPtr item1;
String name;
for (i=1; i<countAddressListsInt; i++){
item1=(DispatchPtr)addressLists.invoke("Item",i);
name=(String)item1.get("Name");
System.out.println("Item "+i+" name is " +name);
}
DispatchPtr globalAddressList=(DispatchPtr)addressLists.invoke("Item",1);
//got the global address List
DispatchPtr
addressEntries=(DispatchPtr)globalAddressList.get("AddressEntries");
System.out.println("Got Address Entries for Global Address List");
//try to get a count
Integer countEntries=(Integer)addressEntries.get("Count");
int countEntriesInt=countEntries.intValue();
System.out.println("There are " + countEntriesInt + " address entries");
DispatchPtr entry=(DispatchPtr)addressEntries.invoke("GetFirst");
String emailAddress=(String)entry.get("Address");
System.out.println("First email address "+emailAddress);
String entryName=(String)entry.get("Name");
System.out.println("Name of entry "+entryName);
//try using the filter...
//!!!!!!!!!ERROR!!!!!!!!!!!!!
// DispatchPtr filter=(DispatchPtr)addressEntries.get("Filter");
//grab a random entry and try to obtain the fields
DispatchPtr entry1=(DispatchPtr)addressEntries.invoke("Item",6666);
String emailAddress1=(String)entry1.get("Address");
System.out.println("First email address "+emailAddress1);
String entryName1=(String)entry1.get("Name");
System.out.println("Name of entry "+entryName1);
String type=(String)entry1.get("Type");
System.out.println("Type "+type);
//!!!!!!!!!ERROR!!!!!!!!!!!!!
// DispatchPtr fields=(DispatchPtr)entry1.get("Fields");
Ole32.CoUninitialize();
} catch (COMException e) {
e.printStackTrace();
}