Share via


Creating a Recipient Using ADSI

Creating a Recipient Using ADSI

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.

The following Active Directory® Service Interfaces (ADSI) example creates a new mail recipient. The accompanying mailbox is created using a CDO for Exchange Management (CDOEXM) interface aggregated onto the ASDI.user object.

Example

Create a mailbox for a mail recipient using ADSI.

Visual Basic

Sub ADSICreateMailBoxRecipient(MDBName As String, _
                               StorageGroup As String, _
                               Server As String, _
                               AdminGroup As String, _
                               Organization As String, _
                               DomainName As String, _
                               emailname As String, _
                               FirstName As String, _
                               LastName As String)

'MDBName is something like "Mailbox Store (MYSTORE)"
'DomainName is something like "DC=MYDOMAIN3,DC=example,DC=com"
'emailname is something like "jamessmith"

'this assumes the MDB to be a mailbox store.


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://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://CN=" + MDBName + _
                               ",CN=" + StorageGroup + _
                               ",CN=InformationStore" + _
                               ",CN=" + Server + _
                               ",CN=Servers" + _
                               ",CN=" + AdminGroup + _
                               ",CN=Administrative Groups" + _
                               ",CN=" + Organization + _
                               ",CN=Microsoft Exchange,CN=Services" + _
                               ",CN=Configuration," + DomainName
objUser.SetInfo

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.