DeleteMailBox Method

DeleteMailBox 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 DeleteMailBox method deletes a mailbox.

Applies To

IMailBoxStore Interface

Type Library

Microsoft CDO for Exchange Management Library

DLL Implemented In

CDOEXM.DLL

Syntax

[Visual Basic]Sub DeleteMailBox
()

[C++]HRESULT DeleteMailBox ();

Return Value

Returns S_OK if successful, or an error value otherwise.

Examples

The following example illustrates the DeleteMailBox method using Collaboration Data Objects (CDO).

[Visual Basic]

Sub DeleteMailboxCDOPerson(strFirstName As String, _ strLastName As String)

Dim oPerson         As New CDO.Person
Dim oMailbox        As CDOEXM.IMailboxStore
Dim strUserName     As String
Dim strURL          As String
Dim strContainerName As String

strUserName = strFirstName & strLastName
strContainerName = "Users"
' Create URL for the user
CreateUserURL(strURL, strContainerName, False, strUserName)

Set oPerson = New CDO.Person
' Bind
oPerson.DataSource.Open strURL

' Delete Mailbox
Set oMailbox = oPerson
oMailbox.DeleteMailbox

' Save
oPerson.DataSource.Save

'CleanUp
Set oPerson = Nothing
Set oMailbox = Nothing

End Sub

The following example illustrates the DeleteMailBox method using Active Directory Service Interfaces (ADSI)

[Visual Basic]

Sub Delete_MailBoxADSI(DCServer As String, _ DomainName As String, _ recipname As String)

'DCServer is something like "DCServer6" 'DomainName is something like "DC=MYDOMAIN3,DC=example,DC=com" 'recipname is something like "jamessmith"

Dim objUser As IADsUser Dim objMailbox As CDOEXM.IMailboxStore

Set objUser = GetObject("LDAP://" + DCServer + _ "/CN=" + recipname + _ ",CN=users," + DomainName)

Set objMailbox = objUser 'check if user is mailbox enabled If objMailbox.HomeMDB = "" Then MsgBox "No mailbox found." Else objMailbox.DeleteMailbox objUser.SetInfo MsgBox "Mailbox for " + recipname + " deleted successfully" End If

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.