Rust
Rust
Attach an Email to Another Email
See more Email Object Examples
Demonstrates the Chilkat Email.AttachEmail method, which attaches a copy of another email to this email object. The attached email is encapsulated in a message/rfc822 subpart. Because a copy is attached, later changes to the source email do not affect the embedded message. This example attaches one email to another.
Background: "Forward as attachment" produces exactly this structure: the original message is embedded whole as a
message/rfc822 part rather than quoted into the body. This preserves the original's headers and formatting intact, which matters for forwarding to a mailbox that will re-parse it, or for reporting spam/phishing with the original evidence attached. Such parts are counted by NumAttachedMessages.Chilkat Rust Downloads
// Demonstrates the AttachEmail method, which attaches a copy of another email to this email
// object. The attached email is encapsulated in a message/rfc822 subpart.
let inner_email = chilkat::Email::new();
inner_email.set_subject("Original message");
inner_email.set_from("alice@example.com");
inner_email.set_body("This is the original message being forwarded.");
let email = chilkat::Email::new();
email.set_subject("FW: Original message");
email.set_from("bob@example.com");
email.set_body("See the attached original email.");
// Attach a copy of the inner email as a message/rfc822 part.
if email.attach_email(&inner_email).is_err() {
println!("{}", email.last_error_text());
return;
}
println!("NumAttachedMessages = {}", email.num_attached_messages());