Platform SDK: Exchange 2000 Server

Creating a Recipient Using ADSI

The following ADSI example creates a new mail recipient. The accompanying mailbox is created using an CDOEXM interface aggregated onto the ASDI.user object.

Example

Create a mailbox for a mail recipient.

[Visual Basic]
Function ADSICreateMailBoxRecipient(ServerName As String, _
                                    DomainName As String, _
                                    emailname As String, _
                                    FirstName As String, _
                                    LastName As String) As Integer

'ServerName is something like "MyServer6"
'DomainName is something like "DC=MYDOMAIN3,DC=microsoft,DC=com"
'emailname is something like "jamessmith"

'this assumes the MDB to be "Private MDB"


Dim objUser As IADsUser
Dim objContainer As IADsContainer
Dim objMailbox As CDOEXM.IMailboxStore
Dim recipname As String, recip As String

recip = "CN=" & emailname

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

' create a recipient
Set objUser = objContainer.Create("User", recip)
objUser.Put "samAccountName", emailname
objUser.Put "sn", LastName
objUser.Put "givenName", FirstName
objUser.Put "userPrincipalName", emailname

objUser.SetInfo
objUser.SetPassword "password"  'let user change it later
objUser.AccountDisabled = False

Set objMailbox = objUser

'Create a mailbox for the recipient
'You cannot create a mailbox using ADSI, so use CDOEXM
objMailbox.CreateMailbox "LDAP://" + ServerName + _
                         "/CN=Private MDB" + _
                         ",CN=First Storage Group,CN=InformationStore,CN=" + _
                         ServerName + _
                         ",CN=Servers,CN=First Administrative Group," + _
                         "CN=Administrative Groups,CN=First Organization," + _
                         "CN=Microsoft Exchange,CN=Services," + _
                         "CN=Configuration," + DomainName
objUser.SetInfo

End Function