CreateMailBox Method

CreateMailBox Method

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 CreateMailBox method creates a mailbox at a specified URL.

Applies To

IMailBoxStore Interface

Type Library

Microsoft CDO for Exchange Management Library

DLL Implemented In

CDOEXM.DLL

Syntax

[Visual Basic]Sub CreateMailBox
(
    HomeMDBURL As String
)

[C++]HRESULT CreateMailBox (     BSTR HomeMDBURL );

Parameters

Return Value

Returns S_OK if successful, or an error value otherwise.

Remarks

The store creates the actual mailbox the first time someone either sends mail to the mailbox or connects to the mailbox. The user object in Microsoft Active Directory is configured immediately.

Examples

The following example illustrates the CreateMailBox method using Collaboration Data Objects (CDO).

[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=OrgName,CN=Microsoft Exchange,CN=Services,CN=Configuration, ' DC=mysubdomain,DC=example,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
' assumes users are in users container, and not an OU
strContainerName = "Users"
' Create URL for the user
CreateUserURL(strURL, strContainerName, False, strUserName)

oPerson.FirstName = strFirstName
oPerson.LastName = strLastName

oPerson.DataSource.SaveTo strURL

Set oPerson = New CDO.Person
' Bind
oPerson.DataSource.Open strURL

' Create Mailbox
Set oMailbox = oPerson
oMailbox.CreateMailbox strHomeMDBUrl

' Save
oPerson.DataSource.Save

'CleanUp
Set oPerson = Nothing
Set oMailbox = Nothing

End Sub

The following example illustrates the CreateMailBox method using Active Directory Service Interfaces (ADSI).

[Visual Basic]

Sub ADSICreateMailBoxRecipient(DCServer As String, _ DomainName As String, _ emailname As String, _ FirstName As String, _ LastName As String)

'DCServer is something like "DCServer6" '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://" & DCServer & "/" & _ "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" 'user should change this later objUser.AccountDisabled = False

Set objMailbox = objUser

'Create a mailbox for the recipient 'You cannot create a mailbox using ADSI, so use CDOEXM 'These values will differ for other organizations objMailbox.CreateMailbox "LDAP://" DCServer & _ "/CN=Mailbox Store (" & _ DCServer & _ "),CN=First Storage Group,CN=InformationStore,CN=" & _ DCServer & _ ",CN=Servers,CN=First Administrative Group," & _ "CN=Administrative Groups,CN=First 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.