MoveMailBox Method

MoveMailBox 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 MoveMailBox method moves a mailbox to a specified URL.

Applies To

IMailBoxStore Interface

Type Library

Microsoft CDO for Exchange Management Library

DLL Implemented In

CDOEXM.DLL

Syntax

[Visual Basic]Sub MoveMailBox
(
    HomeMDBURL As String
)

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

Parameters

  • HomeMDBURL
    The URL to the new mailbox location.

Return Value

Returns S_OK if successful, or an error value otherwise.

Examples

The first example illustrates the MoveMailBox method using Collaboration Data Objects (CDO). The second example illustrates the MoveMailBox method using Active Directory Service Interfaces (ADSI).

CDO

[Visual Basic]

Sub CDOMove_Mailbox(DCServer As String, _ DomainName As String, _ recipname As String, _ Moveto_MDB As String)

'DCServer is something like "DCServer6" '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://" + DCServer + _ "/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) 'these values will differ in other organizations

objMailbox.MoveMailbox "LDAP://" + DCServer + "/CN=" + Moveto_MDB + _ ",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 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

ADSI

[Visual Basic]

Sub ADSIMove_Mailbox(DCServer As String, _ DomainName As String, _ recipname As String, _ Moveto_MDB As String)

'DCServer is something like "DCServer6" '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 objUser As IADsUser Dim objMailbox As CDOEXM.IMailboxStore

On Error GoTo Error

Set objUser = GetObject("LDAP://" + DCServer + _ "/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://" + DCServer + "/CN=" + Moveto_MDB + _ ",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 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.