Sample code for 30+ languages & platforms
JavaScript

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.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat v11.4.0 or greater.
JavaScript
var success = false;

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

var imap = new CkImap();

imap.Ssl = true;
imap.Port = 993;

success = imap.Connect("imap.example.com");
if (success == false) {
    console.log(imap.LastErrorText);
    return;
}

success = imap.Login("user@example.com","myPassword");
if (success == false) {
    console.log(imap.LastErrorText);
    return;
}

//  Delete a mailbox (folder) from the server.
success = imap.DeleteMailbox("OldFolder");
if (success == false) {
    console.log(imap.LastErrorText);
    return;
}

console.log("Mailbox deleted.");

success = imap.Disconnect();
if (success == false) {
    console.log(imap.LastErrorText);
    return;
}