Moving a Mailbox
Moving a Mailbox
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 examples move a mailbox. Note that the second private mailbox store has already been created. LDAP is used to access Active Directory. Modifications in Microsoft® Exchange Server 2003 are handled behind the scenes as part of CDO for Exchange Management (CDOEXM).
Example (CDO)
Visual Basic
Sub CDOMove_Mailbox(MDBName As String, _ DomainName As String, _ recipname As String, _ Moveto_MDB As String, _ Moveto_StorageGroup As String, _ Moveto_Server As String, _ Moveto_AdminGroup As String, _ Organization As String) 'MDBName is something like "MyMDB6" 'DomainName is something like "DC=MYDOMAIN3,DC=example,DC=com" 'recipname is is the e-mail alias (eg. "jamessmith)." 'This assumes you have created the MDB Moveto_MDB (with a name like "PrivateMDB2") Dim objPerson As New CDO.Person Dim objMailbox As CDOEXM.IMailboxStore On Error GoTo Error objPerson.DataSource.Open "LDAP://CN=" + recipname + _ ",CN=users," + DomainName Set objMailbox = objPerson If objMailbox.HomeMDB = "" Then Debug.Print "No mailbox to move." Else Debug.Print "Current MDB: " + objMailbox.HomeMDB 'Moveto_MDB is the MDB name to move the mailbox to (eg. PrivateMDB2) objMailbox.MoveMailbox "LDAP://CN=" + Moveto_MDB + _ ",CN=" + Moveto_StorageGroup + _ ",CN=InformationStore" + _ ",CN=" + Moveto_Server + _ ",CN=Servers" + _ ",CN=" + Moveto_AdminGroup + _ ",CN=Administrative Groups" + _ ",CN=" + Organization + _ ",CN=Microsoft Exchange,CN=Services" + _ ",CN=Configuration," + DomainName objPerson.DataSource.Save Debug.Print "Mailbox has been moved to " + Moveto_MDB + " successfully." End If GoTo Ending Error: If Err.Number = -2147016656 Then Debug.Print "Recipient " + recipname + " does not exist in the default container." MsgBox "Recipient " + recipname + " is not found." Err.Clear Else MsgBox "Run time error: " + Str(Err.Number) + " " + Err.Description Err.Clear End If Ending: End Sub
Example (ADSI)
Visual Basic
Sub ADSIMove_Mailbox(MDBName As String, _ DomainName As String, _ recipname As String, _ Moveto_MDB As String, _ Moveto_StorageGroup As String, _ Moveto_Server As String, _ Moveto_AdminGroup As String, _ Organization As String) 'MDBName is something like "MyMDB6" 'DomainName is something like "DC=MYDOMAIN3,DC=example,DC=com" 'recipname is is the e-mail alias (eg. "jamessmith)." 'This assumes you have created the MDB Moveto_MDB in the same storage group. Dim objUser As IADsUser Dim objMailbox As CDOEXM.IMailboxStore On Error GoTo Error Set objUser = GetObject("LDAP://CN=" + recipname + _ ",CN=users," + DomainName) Set objMailbox = objUser If objMailbox.HomeMDB = "" Then Debug.Print "No mailbox to move." Else Debug.Print "Current MDB: " + objMailbox.HomeMDB 'Moveto_MDB is the MDB name to move the mailbox to (eg. PrivateMDB2) objMailbox.MoveMailbox "LDAP://CN=" + Moveto_MDB + _ ",CN=" + Moveto_StorageGroup + _ ",CN=InformationStore" + _ ",CN=" + Moveto_Server + _ ",CN=Servers" + _ ",CN=" + Moveto_AdminGroup + _ ",CN=Administrative Groups" + _ ",CN=" + Organization + _ ",CN=Microsoft Exchange,CN=Services" + _ ",CN=Configuration," + DomainName objUser.SetInfo Debug.Print "Mailbox has been moved to " + Moveto_MDB + " successfully." End If GoTo Ending Error: If Err.Number = -2147016656 Then Debug.Print "Recipient " + recipname + " does not exist in the default container." MsgBox "Recipient " + recipname + " is not found." Err.Clear Else MsgBox "Run time error: " + Str(Err.Number) + " " + Err.Description Err.Clear End If Ending: 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.