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

Read an attached email

See more Email Object Examples

Open forward-as-attachment.eml from the forwarding example. Read the cover note’s subject, then open each attached message and inspect its own headers and attachment count. This works even when the outer message has no ordinary files.

Chilkat Rust Downloads

Rust

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

let wrapper = chilkat::Email::new();
if wrapper.load_eml("forward-as-attachment.eml").is_err() {
    println!("{}", wrapper.last_error_text());
    return;
}

println!("Cover note: {}", wrapper.subject());
if wrapper.num_attached_messages() == 0 {
    println!("No attached messages.");
    return;
}

let nested = chilkat::Email::new();
let mut i = 0;
while i < wrapper.num_attached_messages() {
    if wrapper.get_attached_email(i, &nested).is_err() {
        println!("{}", wrapper.last_error_text());
        return;
    }

    println!("Original author: {}", nested.from());
    println!("Original subject: {}", nested.subject());
    println!("Files on the original: {}", nested.num_attachments());
    i = i + 1;
}