Zig
Zig
Clear an Email Object
See more Email Object Examples
Demonstrates the Chilkat Email.Clear method, which removes the current message content — recipients, headers, body representations, attachments, related items, and embedded messages — leaving an empty email object. This example builds a message with a recipient and attachment, clears it, and prints the counts before and after.
Background: Reusing a single
Email object across many operations is efficient, but leftover state from a previous message could leak into the next. Clear resets the object completely, giving you a clean slate — the safe way to start a fresh message without allocating a new object.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main() !void {
// Demonstrates the Clear method, which removes the current message content, including
// recipients, headers, body representations, attachments, related items, and embedded
// messages -- leaving an empty email object.
const email = try chilkat.Email.init();
defer email.deinit();
email.setSubject("A message");
email.setBody("Some body text.");
email.addTo("Bob", "bob@example.com") catch {};
email.addStringAttachment("notes.txt", "Some notes.") catch {};
std.debug.print("NumTo before clear = {d}\n", .{email.getNumTo()});
std.debug.print("NumAttachments before clear = {d}\n", .{email.getNumAttachments()});
// Remove all content, resetting the email object.
email.clear();
std.debug.print("NumTo after clear = {d}\n", .{email.getNumTo()});
std.debug.print("NumAttachments after clear = {d}\n", .{email.getNumAttachments()});
}