Home : Retrieve the Members of a Private Distribution List
Q183242 - HOWTO: Retrieve the Members of a Private Distribution List

How to Retrieve the Members of a Private Distribution List

The following piece of code demonstrates how to retrieve the members of Private Distribution List stored in a user's Contacts folder. For more information about any CDO object or method used below, please refer to the Microsoft CDO reference. Before running this code, please ensure that you have first configured CDO.

import com.intrinsyc.cdo.*;
import com.linar.jintegra.Cleaner;

public class RetrievePrivateDLMembers {

    public static void main(String[] args) {
	
	System.setProperty("JINTEGRA_RELEASEALL_SHUTDOWN_HOOK", "");

        //TODO: Change the following parameters based on your setup and configuration
        // the logon parameters of the service account you used to configure CDO
        String domain           = "domain";
        String username         = "username";
        String password         = "password";

        // the DNS name or IP address of the machine where you installed CDO
        String CDOmachine       = "0.0.0.0";

        // the DNS name or IP address of the Exchange Server
        String exchangeServer   = "0.0.0.0";

        // the mailbox you wish to access (NOTE: this is the same as the user's login name
        // e.g., if the username is jsmith, mailbox would also be jsmith )
        String mailbox          = "mailbox";
		
	// field and propset ids
	String CdoPropSetID3 = "0420060000000000C000000000000046";
	String CdoContact_PrivateDLMemberIDs = "0x8054";

        try {
            // use credentials of service account to authenticate to Windows
            com.linar.jintegra.AuthInfo.setDefault(domain, username, password);

            // create a Session in the CDOmachine
            Session session = new Session(CDOmachine);

            // logon to the Exchange Server
            session.logon(null, null, new Boolean(false), new Boolean(true),
                          new Boolean(false), new Boolean(false),
                          exchangeServer + "\n" + mailbox);

            // print the current user for this Session
            AddressEntry user = new AddressEntryProxy(session.getCurrentUser());
            System.out.println("Current user: " + user.getName() + "\n");
			
	    // retrieve the contacts folder
	    Integer folderType = new Integer(CdoDefaultFolderTypes.CdoDefaultFolderContacts);
	    Folder contacts = new FolderProxy(session.getDefaultFolder(folderType));

	    // and get the message collection
	    Messages messages = new MessagesProxy(contacts.getMessages());
	    int count = ((Integer)messages.getCount()).intValue();
	    System.out.println("Contacts Count: " + count);
			
	    // iterate through message collection
	    for (int i = 1; i <= count; i++) {
		Message contactObj = new MessageProxy(messages.getItem(new Integer(i)));
		String contactName = contactObj.getSubject().toString();
		String contactType = contactObj.getType().toString();
		System.out.println(contactName + " -- " + contactType);
				
		// check for IPM.DistList type
		if ( contactObj.getType().toString().compareTo("IPM.DistList") == 0 ) {
		    // extract field containing IDs of members
		    Fields fds = new FieldsProxy(contactObj.getFields());
		    Field fd = new FieldProxy(fds.getItem(CdoContact_PrivateDLMemberIDs, CdoPropSetID3));
		    Object[] fdValue = (Object[])fd.getValue();
		    int fdCount = fdValue.length;
		    System.out.println(" ... Members: " + fdCount);
					
		    // get members' AddressEntry and output name
		    for (int k = 0; k < fdCount; k++) {
			String ID = (String)fdValue[k];
			AddressEntry addr = new AddressEntryProxy(session.getAddressEntry(ID));
			System.out.println(" ...... " + addr.getName().toString());
		    }
		}
	    }
			
	    System.out.println("\nDONE!");

            // log off from the session
            session.logoff();

        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            // clean up and release all references
            com.linar.jintegra.Cleaner.releaseAll();
        }
    }
}

Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.
Created on 11/1/2007.
Last Modified on 11/1/2007.
Last Modified by J-Integra KB Admin.
Article has been viewed 9004 times.
Rated 2 out of 10 based on 3 votes.
Print Article
Email Article