Sample code for 30+ languages & platforms
Rust

Create a multipart/mixed MIME Entity

See more MIME Examples

Demonstrates the Chilkat Mime.NewMultipartMixed method, which initializes the object as an empty multipart/mixed entity, clearing any existing content. It takes no arguments; child parts are then appended.

Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background: multipart/mixed is the container for independent parts shown one after another — the classic "message body plus attachments" layout. Each child is its own distinct content, unlike multipart/alternative (competing renderings of the same thing) or multipart/related (a part and its embedded resources). Start here, then AppendPart a body and AppendPartFromFile the attachments.

Chilkat Rust Downloads

Rust

// Demonstrates the Mime.NewMultipartMixed method, which initializes the object as an empty
// multipart/mixed entity, clearing any existing headers, body, and child parts.  It takes no
// arguments.

let mime = chilkat::Mime::new();

if mime.new_multipart_mixed().is_err() {
    println!("{}", mime.last_error_text());
    return;
}

// Append child parts.  multipart/mixed is the container for a message body plus attachments.
let body_part = chilkat::Mime::new();
if body_part.set_body_from_plain_text("See the attached report.").is_err() {
    println!("{}", body_part.last_error_text());
    return;
}

if mime.append_part(&body_part).is_err() {
    println!("{}", mime.last_error_text());
    return;
}

if mime.append_part_from_file("qa_data/report.pdf").is_err() {
    println!("{}", mime.last_error_text());
    return;
}

println!("Number of parts: {}", mime.num_parts());