Sample code for 30+ languages & platforms
Rust

Save Email Attachments to Filesystem

Saves email attachments to a directory.

Chilkat Rust Downloads

Rust

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

// Load an email object containing attachments.
// This .eml can be downloaded from:
// http://www.example-code.com/testData/HtmlEmail.eml

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

// If OverwriteExisting is turned on, files with the same
// name are overwritten.  If turned off, new/unique filenames
// are automatically generated.  The filenames actually saved
// are accessible via the GetAttachmentFilename method.
email.set_overwrite_existing(true);

// Save all attachments to the "myAttachments" subdirectory
// found under the calling process's current working directory.
// This directory is automatically created if it does not already
// exist.
if email.save_all_attachments("myAttachments").is_err() {
    println!("{}", email.last_error_text());
    return;
}

// List the attachment filenames:
for i in 0..email.num_attachments() {
    println!("{}", email.get_attachment_filename(i).unwrap_or_default());
}