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

Create an HTML preview with embedded images

See more Email Object Examples

Make an independent copy of with-attachments.eml, remove ordinary file attachments from the copy, and export its HTML with related images as data URLs. The original retains its attachments. Use a sanitized viewer when showing untrusted HTML.

Chilkat Rust Downloads

Rust

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

let email = chilkat::Email::new();
if email.load_eml("with-attachments.eml").is_err() {
    println!("{}", email.last_error_text());
    return;
}

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

// Keep related items: the HTML still refers to them.
preview.drop_attachments();
println!("Files in original: {}  Files in preview: {}", email.num_attachments(), preview.num_attachments());
if !preview.has_html_body() {
    println!("This message has no HTML preview.");
    return;
}

let html = chilkat::StringBuilder::new();
if preview.get_html_body_sb(true, &html).is_err() {
    println!("{}", preview.last_error_text());
    return;
}

if html.write_file("preview.html", "utf-8", false).is_err() {
    println!("Failed: html.WriteFile.");
    return;
}

println!("Saved preview.html.");