Platform SDK: Exchange 2000 Server

CreateMailBox Method

[This is preliminary documentation and subject to change.]

This method creates a mailbox at a specified URL.

[Visual Basic,VBScript]
Function CreateMailBox(HomeMDBURL As String)
[C++]
HRESULT CreateMailBox(BSTR HomeMDBURL);
[IDL]
HRESULT CreateMailBox([in] BSTR HomeMDBURL);
HomeMDBURL
The URL to the new mailbox. This value can be saved as a standard email name or as a DN value. See Email Addresses Stored as Active Directory Paths for more information.

Remarks

The store creates the actual mailbox the first time someone either sends mail to the mailbox or connects to the mailbox.

Example (CDO)

[Visual Basic]
Sub CDOCreateMailBoxRecipient(ServerName As String, _
                              DomainName As String, _
                              emailname As String, _
                              FirstName As String, _
                              LastName As String)
                                        
'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 objPerson As New CDO.Person
Dim objMailbox As CDOEXM.IMailboxStore

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://" + ServerName + _
                            "/CN=" + emailname + _
                            ",CN=users," + DomainName


Set objMailbox = objPerson
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

objPerson.DataSource.Save

End Sub

Example (ADSI)

[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