Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oImap

nSuccess := 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.

oImap := CreateObject("Chilkat.Imap")

oImap:Ssl := 1
oImap:Port := 993

nSuccess := oImap:Connect("imap.example.com")
IF (nSuccess == 0)
    ? oImap:LastErrorText
    oImap:destroy()
    RETURN
ENDIF

nSuccess := oImap:Login("user@example.com", "myPassword")
IF (nSuccess == 0)
    ? oImap:LastErrorText
    oImap:destroy()
    RETURN
ENDIF

//  Delete a mailbox (folder) from the server.
nSuccess := oImap:DeleteMailbox("OldFolder")
IF (nSuccess == 0)
    ? oImap:LastErrorText
    oImap:destroy()
    RETURN
ENDIF

? "Mailbox deleted."

nSuccess := oImap:Disconnect()
IF (nSuccess == 0)
    ? oImap:LastErrorText
    oImap:destroy()
    RETURN
ENDIF

oImap:destroy()