Sample code for 30+ languages & platforms
Rust

Subscribe to an IMAP Mailbox

See more IMAP Examples

Demonstrates the Chilkat Imap.Subscribe method, which subscribes the authenticated IMAP account to a mailbox. Subscription controls which mailboxes are returned by subscribed-mailbox listings. This example subscribes to a mailbox.

Background: An account can have many mailboxes, but a user often cares about only some of them. IMAP's subscription list is that curated set: mail clients typically show subscribed folders by default and hide the rest. Subscribing does not create or change a mailbox — it only adds it to the "show me this one" list (retrieved with a subscribed-only listing). Unsubscribe removes it from that list.

Chilkat Rust Downloads

Rust

// Demonstrates the Imap.Subscribe method, which subscribes the authenticated IMAP account to
// a mailbox.  Subscription controls which mailboxes are returned by subscribed-mailbox
// listings.

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;
}

// Subscribe to a mailbox.
if imap.subscribe("Archive2026").is_err() {
    println!("{}", imap.last_error_text());
    return;
}

println!("Subscribed to the mailbox.");

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