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

Download POP3 Email using UIDLs

Demonstrates how to download POP3 email by first getting the complete set of UIDLs and then downloading email by calling FetchByUIDL for each UIDL.

Chilkat Rust Downloads

Rust

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

// The mailman object is used for receiving (POP3) 
// and sending (SMTP) email.
let mailman = chilkat::MailMan::new();

// Set the POP3 server's hostname
mailman.set_mail_host("pop.example.com");

// Set the POP3 login/password.
mailman.set_pop_username("myLogin");
mailman.set_pop_password("myPassword");

let st_uidls = chilkat::StringTable::new();
if mailman.fetch_uidls(&st_uidls).is_err() {
    println!("{}", mailman.last_error_text());
    return;
}

let email = chilkat::Email::new();

let count = st_uidls.count();
let mut i = 0;
while i < count {
    // Download the full email.
    if mailman.fetch_by_uidl(&st_uidls.string_at(i).unwrap_or_default(), false, 0, &email).is_err() {
        println!("{}", mailman.last_error_text());
        return;
    }

    println!("{}", i);
    println!("From: {}", email.from());
    println!("Subject: {}", email.subject());

    i = i + 1;
}

let _ = mailman.pop3_end_session();