Rust
Rust
Clear an Email Object
See more Email Object Examples
Demonstrates the Chilkat Email.Clear method, which removes the current message content — recipients, headers, body representations, attachments, related items, and embedded messages — leaving an empty email object. This example builds a message with a recipient and attachment, clears it, and prints the counts before and after.
Background: Reusing a single
Email object across many operations is efficient, but leftover state from a previous message could leak into the next. Clear resets the object completely, giving you a clean slate — the safe way to start a fresh message without allocating a new object.Chilkat Rust Downloads
// Demonstrates the Clear method, which removes the current message content, including
// recipients, headers, body representations, attachments, related items, and embedded
// messages -- leaving an empty email object.
let email = chilkat::Email::new();
email.set_subject("A message");
email.set_body("Some body text.");
let _ = email.add_to("Bob", "bob@example.com");
let _ = email.add_string_attachment("notes.txt", "Some notes.");
println!("NumTo before clear = {}", email.num_to());
println!("NumAttachments before clear = {}", email.num_attachments());
// Remove all content, resetting the email object.
email.clear();
println!("NumTo after clear = {}", email.num_to());
println!("NumAttachments after clear = {}", email.num_attachments());