Rust
Rust
Render an Email to MIME Bytes in a BinData
See more SMTP Examples
Demonstrates the Chilkat MailMan.RenderToMimeBd method, which renders an Email object as MIME bytes and appends the result to a BinData, without sending the email. This example renders a message into a BinData and prints the byte count.
Background: This is the binary version of
RenderToMime. A BinData holds raw bytes, which is the right container when you want the rendered MIME as binary — to write it directly to a file or socket, hash it, or hand it to another API expecting a byte buffer — rather than as text.Chilkat Rust Downloads
// Demonstrates the MailMan.RenderToMimeBd method, which renders an Email object as MIME
// bytes and appends the result to a BinData (without sending the email).
let mailman = chilkat::MailMan::new();
// Build the email to render.
let email = chilkat::Email::new();
email.set_subject("Rendered email");
email.set_from("alice@example.com");
let _ = email.add_to("Bob", "bob@example.com");
email.set_body("This message is rendered to MIME bytes in a BinData.");
// Render the MIME into a BinData.
let bd_mime = chilkat::BinData::new();
if mailman.render_to_mime_bd(&email, &bd_mime).is_err() {
println!("{}", mailman.last_error_text());
return;
}
println!("Rendered MIME size (bytes) = {}", bd_mime.num_bytes());