Sample code for 30+ languages & platforms
Rust

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 Rust Downloads

Rust

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

let imap = chilkat::Imap::new();

imap.set_ssl(true);
imap.set_port(993);

if imap.connect("imap.example.com").is_err() {
    println!("{}", imap.last_error_text());
    return;
}

if imap.login("user@example.com", "myPassword").is_err() {
    println!("{}", imap.last_error_text());
    return;
}

// Delete a mailbox (folder) from the server.
if imap.delete_mailbox("OldFolder").is_err() {
    println!("{}", imap.last_error_text());
    return;
}

println!("Mailbox deleted.");

if imap.disconnect().is_err() {
    println!("{}", imap.last_error_text());
    return;
}