Zig
Zig
Get an Email's MIME into a StringBuilder
See more Email Object Examples
Demonstrates the Chilkat Email.GetMimeSb method, which returns the email as MIME text (header, body or bodies, related items, and all attachments) by appending it to a StringBuilder object. This example builds a message and appends its MIME to a StringBuilder.
Background: This is a
StringBuilder-based alternative to GetMime, which returns a plain string. Writing into a StringBuilder is more efficient when the MIME is large or when you intend to further manipulate it — searching, replacing, or accumulating additional text — without creating many intermediate string copies.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 GetMimeSb method, which returns the email as MIME text (headers, bodies,
// related items, and attachments), appending it to a StringBuilder object.
const email = try chilkat.Email.init();
defer email.deinit();
email.setSubject("GetMimeSb example");
email.setFrom("alice@example.com");
email.addTo("Bob", "bob@example.com") catch {};
email.setBody("Hello!");
// Append the complete MIME to a StringBuilder.
const sb_mime = try chilkat.StringBuilder.init();
defer sb_mime.deinit();
email.getMimeSb(sb_mime) catch {
std.debug.print("{s}\n", .{try email.getLastErrorText(alloc)});
return;
};
std.debug.print("{s}\n", .{try sb_mime.getAsString(alloc)});
}