Platform SDK: Exchange Server

Phone List Sample Code

' This code modifies the Phone number property of a mailbox. By 
' default, all users have access to modify this property on their own 
' mailbox.
' This following code will cause the browser to display a user 
' identification dialog. The IIS server's password authentication must 
' be set to Allow Anonymous and Basic (Clear Text) only. This way, the 
' browser will be able to use the correct security context when using 
' the GetObject method.

Dim strAT ' Authorization Type information
strAT = Request.ServerVariables("AUTH_TYPE")
If InStr(1, "_BasicNTLM", strAT, 1) < 2 Then
  Response.Buffer = True
  Response.Status = ("401 Unauthorized")
  Response.End
End If
Dim strMailboxPath        ' ADsPath to the user's mailbox
Dim strServer             ' name of the Microsoft Exchange 5.5 server
Dim intPosPrefix          ' numeric index used used to build ADsPath to schema object
Dim intPosSuffix          ' numeric index used used to build ADsPath to schema object
Dim strPrefix             ' prefix string used to build ADsPath to schema object
Dim strSuffix             ' suffix string used to build ADsPath to schema object
Dim strPathToSchemaObject ' ADsPath to the schema object
Dim objMailbox            ' mailbox object
Dim strNewPoneNumber      ' value of the new phone number
Function isUserEditable(strSchemaObjectPath)
  Dim objSchemaObject     ' schema object
  Dim intValue            ' value of the 'Access-Category' property
  Set objSchemaObject = GetObject(strSchemaObjectPath)
  intValue = objSchemaObject.Get("Access-Category")
  If intValue = 2 Then    ' user may modify the mailbox property
    isUserEditable = True
  Else                    ' the value was 0, 1, or 3
    isUserEditable = False
  End If
End Function

' The following procedure modifies the property of an object that
' contains a string value. To set a property to the empty string, 
' you must remove it from the object:

Sub ModifyProperty(strNewValue, strADsProperty)
  On Error Resume Next
  If Len(strNewValue) <> 0 Then
    objMailbox.Put strADsProperty, CStr(strNewValue)
  Else  ' The new value is empty
    objIADs.Get (strADsProperty)

' If the property doesn't exist on the object, an error will be 
' generated:

    If Err.Number = 0 Then 
' the property exists on the object and must be removed
      objMailbox.PutEx ADS_PROPERTY_CLEAR, strADsProperty, CStr(" ")
    End If
    Err.Clear
  End If
End Sub
Const ADS_PROPERTY_CLEAR = 1  
' used by the PutEx method to clear a property from an object
strMailboxPath = "LDAP://SPARKER1/cn=SParker,cn=Recipients,ou=3081,o=16"
strServer = "sparker1"
strNewPoneNumber = "(425) 882-8080 x 13882"
intPosPrefix = InStr(strMailboxPath, "/cn")
intPosSuffix = InStr(strMailboxPath, "ou")
strPrefix = Mid(strMailboxPath, 1, intPosPrefix - 1) + "/cn="
strSuffix = ",cn=Microsoft DMD," + Mid(strMailboxPath, intPosSuffix, Len(strMailboxPath))
strPathToSchemaObject = strPrefix + "Telephone-Office1" + strSuffix
If isUserEditable(strPathToSchemaObject) Then
  Set objMailbox = GetObject(strMailboxPath)
  ModifyProperty strNewPoneNumber, "telephoneNumber"
  objMailbox.SetInfo  ' save the object information
  Response.Write "Phone number modified successfully :)<BR>"
Else
  Response.Write "You don't have permissions to modify your phone number :(<BR>"
End If
%>