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

Preview POP3 messages and download a complete email

See more Email Object Examples

Read a short preview for each of up to five messages into an EmailBundle, print their subjects, and download the complete first entry into a separate Email. Configure a POP3 account that supports UIDL and TOP. All messages stay on the server.

Chilkat Rust Downloads

Rust

// Assumes Chilkat is unlocked. See Global Unlock Sample.

let mail = chilkat::MailMan::new();
mail.set_mail_host("pop.example.com");
mail.set_mail_port(995);
mail.set_pop_ssl(true);
mail.set_require_ssl_cert_verify(true);
mail.set_pop_username("MAIL_USER");
mail.set_pop_password("MAIL_PASSWORD");
let previews = chilkat::EmailBundle::new();
// Keep the messages and request minimal previews. Range indexes are zero-based and inclusive.
if mail.fetch_range(true, true, 0, 0, 4, &previews).is_err() {
    println!("{}", mail.last_error_text());
    return;
}

if previews.message_count() == 0 {
    println!("There are no messages to preview.");
    if mail.pop3_end_session().is_err() {
        println!("{}", mail.last_error_text());
        return;
    }

    return;
}

let header = chilkat::Email::new();
let mut i = 0;
while i < previews.message_count() {
    if previews.email_at(i, &header).is_err() {
        println!("{}", previews.last_error_text());
        return;
    }

    println!("{}  {}", header.uidl(), header.subject());
    i = i + 1;
}

// A UI could use its selected row here. FetchFull uses the preview's POP3 identity.
if previews.email_at(0, &header).is_err() {
    println!("{}", previews.last_error_text());
    return;
}

let email = chilkat::Email::new();
if mail.fetch_full(&header, &email).is_err() {
    println!("{}", mail.last_error_text());
    return;
}

if mail.pop3_end_session().is_err() {
    println!("{}", mail.last_error_text());
    return;
}

println!("Full message: {}  Files: {}", email.subject(), email.num_attachments());

if email.save_eml("pop-received.eml").is_err() {
    println!("{}", email.last_error_text());
    return;
}

println!("Saved pop-received.eml.");