Platform SDK: Exchange 2000 Server

MoveMailBox Method

[This is preliminary documentation and subject to change.]

This method moves a mailbox to a specified URL.

[Visual Basic,VBScript]
Function MoveMailBox(HomeMDBURLAs String)
[C++]
HRESULT MoveMailBox(BSTR HomeMDBURL);
[IDL]
HRESULT MoveMailBox([in] BSTR HomeMDBURL);
HomeMDBURL
The URL to the new mailbox location. 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

Example (CDO)

[Visual Basic]
Sub CDOMove_Mailbox(ServerName As String, _
                    DomainName As String, _
                    recipname As String, _
                    Moveto_MDB As String)

'ServerName is something like "MyServer6"
'DomainName is something like "DC=MYDOMAIN3,DC=microsoft,DC=com"
'recipname is is the email 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://" + ServerName + _
                            "/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://" + ServerName + "/CN=" + Moveto_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
  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(ServerName As String, _
                     DomainName As String, _
                     recipname As String, _
                     Moveto_MDB As String)

'ServerName is something like "MyServer6"
'DomainName is something like "DC=MYDOMAIN3,DC=microsoft,DC=com"
'recipname is is the email 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://" + ServerName + _
                        "/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://" + ServerName + "/CN=" + Moveto_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
  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