Sample code for 30+ languages & platforms
Rust

Add File Attachments to an Email

Demonstrates how to add one or more file attachments to an email.

Chilkat Rust Downloads

Rust

let email = chilkat::Email::new();

email.set_subject("This is a test");
email.set_body("This is a test");
email.set_from("support@chilkatsoft.com");
let _ = email.add_to("Chilkat Admin", "admin@chilkatsoft.com").is_ok();

// To add file attachments to an email, call AddFileAttachment
// once for each file to be attached.  The method returns
// the content-type of the attachment if successful, otherwise
// returns cknull

let _ = email.add_file_attachment("something.pdf").unwrap_or_default();
if !email.last_method_success() {
    println!("{}", email.last_error_text());
    return;
}

let _ = email.add_file_attachment("something.xml").unwrap_or_default();
if !email.last_method_success() {
    println!("{}", email.last_error_text());
    return;
}

let _ = email.add_file_attachment("something.zip").unwrap_or_default();
if !email.last_method_success() {
    println!("{}", email.last_error_text());
    return;
}

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

println!("Saved EML!");