Share via


Enumerating Contacts

Enumerating Contacts

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Example

This example lists the contacts in the "Users" container in the Active Directory. The example opens contact information in Active Directory by using Active Directory® Service Interfaces (ADSI). It then uses the IMailRecipient interface aggregated onto the ADSI contacts object to access information about the e-mail address for each contact.

Visual Basic

Sub List_Contacts(DomainName As String)

'DomainName is something like "DC=MYDOMAIN3,DC=example,DC=com"

Dim objContact As IADs
Dim objContainer As IADsContainer
Dim objRecip As CDOEXM.MailRecipient
Dim i As Long
Dim name As String

On Error GoTo Error
' get the user container. Note that user information can also
' be stored in other organizational units (ou).
Set objContainer = GetObject("LDAP://CN=users," + DomainName)
objContainer.Filter = Array("Contact")
i = 0
Debug.Print
For Each objContact In objContainer
   name = objContact.name
   name = Right(name, Len(name) - 3)
   Set objRecip = objContact
   If objRecip.TargetAddress = "" And objRecip.X400Email = "" Then
      Debug.Print name + "   (mail disabled)"
   Else
      Debug.Print name + "   (mail enabled)"
   End If
   i = i + 1
Next
Debug.Print "Number of contacts found in the DS (in the default container): " + Str(i)
GoTo Ending

Error:
   Debug.Print "Failed while displaying the contacts in the default container."
   MsgBox "Run time error: " + Str(Err.Number) + " " + Err.Description
   Err.Clear

Ending:

End Sub

Send us your feedback about the Microsoft Exchange Server 2003 SDK.

Build: June 2007 (2007.618.1)

© 2003-2006 Microsoft Corporation. All rights reserved. Terms of use.