Platform SDK: Exchange 2000 Server

Enumerating Contacts

[This is preliminary documentation and subject to change.]

Example

This example lists the contacts in an Exchange 2000 information store. This example opens contact information in the Active Directory using ADSI. It then uses the IMailRecipient interface aggregated onto the ADSI.contacts object to access information in the Web Store.

[Visual Basic]

Sub List_Contacts(ServerName As String, DomainName As String)

'ServerName is something like "MyServer6"
'DomainName is something like "DC=MYDOMAIN3,DC=microsoft,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 container
Set objContainer = GetObject("LDAP://" + ServerName + "/" + _
                            "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