Platform SDK: Exchange 2000 Server

Creating a Contact

[This is preliminary documentation and subject to change.]

The following examples create a mail-enabled contact. The IMailRecipient interface is aggregated onto the respective CDO and ADSI objects. Note that the LDAP protocol accesses the Active Directory. Any information that needs to be updated in the Exchange 2000 Server is updated behind the scenes as part of CDOEXM management.

Example (CDO)

[Visual Basic]
Sub CreateCDO_ContactObject(ServerName As String, _
                                 DomainName As String, _
                                 recipname As String, _
                                 ForwardingDomain As String, _
                                 FirstName As String, _
                                 LastName As String)
                                        
'ServerName is something like "MyServer6"
'DomainName is something like "DC=MYDOMAIN3,DC=microsoft,DC=com"
'recipname is is the email alias eg. "jamessmith"
'ForwardingDomain is a domain like "somewhere.microsoft.com"

Dim objPerson As New CDO.Person
Dim objRecip As CDOEXM.IMailRecipient

objPerson.FirstName = FirstName
objPerson.LastName = LastName
objPerson.Fields("objectClass") = "contact"
objPerson.Fields.Update
objPerson.DataSource.SaveTo "LDAP://" + ServerName + _
                            "/CN=" + recipname + _
                            ",CN=users," + DomainName
objPerson.Fields.Update

Dim FwdAddress As String
FwdAddress = "smtp:" + recipname + "@" + ForwardingDomain

Set objRecip = objPerson
objRecip.MailEnable FwdAddress

objPerson.DataSource.Save

End Sub

Example (ADSI)

[Visual Basic]
Sub CreateADSI_Contact(ServerName As String, _
                       DomainName As String, _
                       recipname As String, _
                       ForwardingDomain As String, _
                       FirstName As String, _
                       LastName As String)

'ServerName is something like "MyServer6"
'DomainName is something like "DC=MYDOMAIN3,DC=microsoft,DC=com"
'recipname is is the email alias eg. "jamessmith"
'ForwardingDomain is a domain like "somewhere.microsoft.com"

Dim objContact As IADs
Dim objContainer As IADsContainer
Dim objRecip As CDOEXM.MailRecipient
Dim recip As String

'recipname is contact name (eg. jamessmith)
'ForwardingAddress is full forwarding address,
'such as jamessmith@somewhere_else.microsoft.com
recip = "CN=" & recipname

' get the container
Set objContainer = GetObject("LDAP://" + ServerName + "/" + _
                            "CN=users," + DomainName)

' create a Contact
Set objContact = objContainer.Create("contact", recip)
objContact.Put "sn", recipname
objContact.Put "givenName", recipname
objContact.SetInfo

Set objRecip = objContact
Dim FwdAddress As String
FwdAddress = "smtp:" + recipname + "@" + ForwardingDomain
objRecip.MailEnable FwdAddress
objContact.SetInfo


End Sub