Share via


Creating a Mailbox-Enabled Recipient

Creating a Mailbox-Enabled Recipient

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.

In the following example, a new recipient and an accompanying mailbox are created. The IMailboxStore interface is aggregated onto the Person object. This allows the person information to be used when creating the mailbox.

Example (CDOEXM)

Create a mailbox for a mail recipient. The example uses the CreateUserURL subroutine, which is described in the topic Creating a User URL.

Visual Basic

Sub CreateMailboxCDOPerson(strFirstName As String, _
                                   strLastName As String, _
                                   strHomeMDBUrl As String)
' strHomeMDBUrl should look like this
' strHomeMDBUrl = "CN=Mailbox Store (MYSTORE),CN=First Storage Group,
'                 CN=InformationStore,CN=MYSTORE,CN=Servers,
'                 CN=First Administrative Group,CN=Administrative Groups,
'                 CN=IASI,CN=Microsoft Exchange,CN=Services,CN=Configuration,
'                 DC=mydomain,DC=fourthcoffee,DC=com"

    Dim oPerson         As New CDO.Person
    Dim oMailbox        As CDOEXM.IMailboxStore
    Dim strUserName     As String
    Dim strURL          As String
    Dim strContainerName As String

    strUserName = strFirstName & strLastName

    strContainerName = "Users"
    ' Create a URL for the user.
    CreateUserURL strURL, strContainerName, False, strUserName

    oPerson.FirstName = strFirstName
    oPerson.LastName = strLastName

    oPerson.DataSource.SaveTo strURL

    ' Create a mailbox.
    Set oMailbox = oPerson
    oMailbox.CreateMailbox strHomeMDBUrl

    ' Save.
    oPerson.DataSource.Save

    ' Clean up.
    Set oPerson = Nothing
    Set oMailbox = Nothing

End Sub



VBScript

Sub CDOCreateMailBoxRecipient(MDBName, _
                              domainName, _
                              exchangeOrg, _
                              adminGroup, _
                              storageGroup, _
                              storeName, _
                              emailname, _
                              firstName, _
                              lastName)

' MDBName      - the MDB name, for example "MyMDB6"
' domainName   - the server's domain, for example "MYDOMAIN3.microsoft.com"
' exchangeOrg  - the Exchange organization housing the mailbox store. For example "First
'                Organization"
' adminGroup   - the Exchange administrative group name, for example "First Administrative Group"
' storageGroup - the storage group for the mailbox store, for example "First Storage Group"
' storeName    - the mailbox store name, for example "Mailbox Store (SERVERNAME)"
' emailname    - the user's e-mail name, for example "jamessmith"
' firstName    - the user's first name, for example "James"
' lastName     - the user's last name, for example "Smith"


 Dim objPerson
 Set objPerson = CreateObject("CDO.Person")
 Dim objMailbox

 Dim domTokens
 domTokens     = split(domainName,".",-1,1)
 domainDN      = join(domTokens,",dc=")
 domainDN      = "dc=" & domainDN


 ' First, create the user in Active Directory.
 objPerson.FirstName = FirstName
 objPerson.LastName  = LastName
 objPerson.Fields("userPrincipalName") = LastName
 objPerson.Fields("userAccountControl") = 512
 objPerson.Fields("userPassword") = "password"
 objPerson.Fields.Update
 objPerson.DataSource.SaveTo "LDAP://CN=" + MDBName + _
                            ",CN=" + emailname + _
                            ",CN=users," + domainDN


 ' Now, create a mailbox in a specified location.

 Set objMailbox = objPerson.GetInterface("IMailboxStore")
 objMailbox.CreateMailbox "LDAP://CN=" + _
                         MDBName + _
                         ",CN=" + _
                         StoreName + _
                         ",CN=" + _
                         StorageGroup + ",CN=InformationStore,CN=" + _
                         ServerName + _
                         ",CN=Servers,CN=" + _
                         AdminGroup + "," + _
                         "CN=Administrative Groups,CN=" + _
                         ExchangeOrg + "," + _
                         "CN=Microsoft Exchange,CN=Services," + _
                         "CN=Configuration," + domainDN

 objPerson.DataSource.Save

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.