Zig
Zig
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 Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// Demonstrates the MailMan.RenderToMimeBd method, which renders an Email object as MIME
// bytes and appends the result to a BinData (without sending the email).
const mailman = try chilkat.MailMan.init();
defer mailman.deinit();
// Build the email to render.
const email = try chilkat.Email.init();
defer email.deinit();
email.setSubject("Rendered email");
email.setFrom("alice@example.com");
email.addTo("Bob", "bob@example.com") catch {};
email.setBody("This message is rendered to MIME bytes in a BinData.");
// Render the MIME into a BinData.
const bd_mime = try chilkat.BinData.init();
defer bd_mime.deinit();
mailman.renderToMimeBd(email, bd_mime) catch {
std.debug.print("{s}\n", .{try mailman.getLastErrorText(alloc)});
return;
};
std.debug.print("Rendered MIME size (bytes) = {d}\n", .{bd_mime.getNumBytes()});
}