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

Download POP3 Email to MIME

Download the email from a POP3 mailbox directly into MIME, without parsing into email objects.

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");

// First, get the complete set of UIDLs for the email in the POP3 mailbox:
let st_uidls = chilkat::StringTable::new();
if mailman.fetch_uidls(&st_uidls).is_err() {
    println!("{}", mailman.last_error_text());
    return;
}

// Download each email as MIME.
// If desired, the MIME can be loaded into an email object.
let bd_mime = chilkat::BinData::new();
let email = chilkat::Email::new();

let count = st_uidls.count();
let mut i = 0;
while i < count {
    if mailman.fetch_mime_bd(&st_uidls.string_at(i).unwrap_or_default(), &bd_mime).is_err() {
        println!("{}", mailman.last_error_text());
        return;
    }

    let _ = email.set_from_mime_bd(&bd_mime);
    println!("From: {}", email.from());
    println!("Subject: {}", email.subject());

    i = i + 1;
}