Zig
Zig
Make a Copy of an Email
See more Email Object Examples
Demonstrates the Chilkat Email.MakeCopy method, which copies the entire state of this email into another Email object — message content, recipients, headers, body representations, attachments, and related items. This example copies an email and reads a couple of fields from the copy.
Background: A deep copy gives you an independent duplicate: changes to one object do not affect the other. This is handy for template-and-tweak workflows — build a base message once, copy it per recipient, then vary only the recipient or a few fields — without risk of one send's edits bleeding into the next.
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 MakeCopy method, which copies the entire state of this email into
// another Email object -- message content, recipients, headers, bodies, attachments, and
// related items.
const email = try chilkat.Email.init();
defer email.deinit();
email.setSubject("Original");
email.setFrom("alice@example.com");
email.addTo("Bob", "bob@example.com") catch {};
email.setBody("Original body.");
// Copy the entire email into a new Email object.
const copy = try chilkat.Email.init();
defer copy.deinit();
email.makeCopy(copy) catch {
std.debug.print("{s}\n", .{try email.getLastErrorText(alloc)});
return;
};
std.debug.print("Copy subject: {s}\n", .{try copy.getSubject(alloc)});
std.debug.print("Copy NumTo: {d}\n", .{copy.getNumTo()});
}