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

Create, save, and reopen a plain-text email

See more Email Object Examples

Set the sender, recipient, subject, and plain-text body. Save the result as an EML file, then open it in a second Email object and read its contents.

Chilkat Rust Downloads

Rust

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

let email = chilkat::Email::new();
email.set_from("Sam Lee <sam@example.com>");
if email.add_to("Alex Rivera", "alex@example.net").is_err() {
    println!("{}", email.last_error_text());
    return;
}

email.set_subject("Hello");
email.set_body("This is a plain-text message.");
if email.save_eml("message.eml").is_err() {
    println!("{}", email.last_error_text());
    return;
}

let received = chilkat::Email::new();
if received.load_eml("message.eml").is_err() {
    println!("{}", received.last_error_text());
    return;
}

println!("{}", received.from());
println!("{}", received.subject());
println!("{}", received.get_plain_text_body().unwrap_or_default());