Platform SDK: Exchange 2000 Server

Moving a Mailbox

[This is preliminary documentation and subject to change.]

The following examples move a mailbox. Note that the second private mailbox store has already been created. LDAP protocol is used to access the Microsoft® Windows® Active Directory™. Modifications within the Microsoft® Exchange 2000 Server are handled behind the scenes as part of CDOEXM management.

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