Sample code for 30+ languages & platforms
Visual Basic 6.0

Delete an IMAP Mailbox

See more IMAP Examples

Demonstrates the Chilkat Imap.DeleteMailbox method, which deletes a mailbox from the IMAP server. This deletes the mailbox itself, not merely the messages it contains. This example deletes a mailbox named OldFolder.

Background: Deleting a mailbox removes the folder and everything in it — an irreversible action, so applications typically confirm first. Server rules can add constraints: some refuse to delete a folder that still has child folders, or that is currently selected. This is the counterpart to CreateMailbox; to remove individual messages rather than a whole folder, mark them deleted and Expunge.

Chilkat Visual Basic 6.0 Downloads

Visual Basic 6.0
Dim success As Long
success = 0

'  Demonstrates the Imap.DeleteMailbox method, which deletes a mailbox from the IMAP server.
'  This deletes the mailbox itself, not merely the messages it contains.

Dim imap As New ChilkatImap

imap.Ssl = 1
imap.Port = 993

success = imap.Connect("imap.example.com")
If (success = 0) Then
    Debug.Print imap.LastErrorText
    Exit Sub
End If

success = imap.Login("user@example.com","myPassword")
If (success = 0) Then
    Debug.Print imap.LastErrorText
    Exit Sub
End If

'  Delete a mailbox (folder) from the server.
success = imap.DeleteMailbox("OldFolder")
If (success = 0) Then
    Debug.Print imap.LastErrorText
    Exit Sub
End If

Debug.Print "Mailbox deleted."

success = imap.Disconnect()
If (success = 0) Then
    Debug.Print imap.LastErrorText
    Exit Sub
End If