Sample code for 30+ languages & platforms
Rust Requires Chilkat v11.0.0+

List Email UIDs

List the UIDs of each email in a mailbox.

Chilkat Rust Downloads

Rust

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

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

// Connect to an IMAP server.
// Use TLS
imap.set_ssl(true);
imap.set_port(993);
if imap.connect("MY-IMAP-DOMAIN").is_err() {
    println!("{}", imap.last_error_text());
    return;
}

// Login
if imap.login("MY-IMAP-LOGIN", "MY-IMAP-PASSWORD").is_err() {
    println!("{}", imap.last_error_text());
    return;
}

// Select an IMAP mailbox
if imap.select_mailbox("Inbox").is_err() {
    println!("{}", imap.last_error_text());
    return;
}

// Get the message IDs of all the emails in the mailbox
// We can choose to fetch UIDs or sequence numbers.
let fetch_uids = true;
let message_set = chilkat::MessageSet::new();
if imap.query_mbx("ALL", fetch_uids, &message_set).is_err() {
    println!("{}", imap.last_error_text());
    return;
}

let mut i = 0;
let n = message_set.count();
while i < n {
    println!("{}", message_set.get_id(i));
    i = i + 1;
}

// Disconnect from the IMAP server.
let _ = imap.disconnect().is_ok();