Sample code for 30+ languages & platforms
Zig

Save an Email to a Chilkat XML File

See more Email Object Examples

Demonstrates the Chilkat Email.SaveXml method, which converts the email object to Chilkat's XML representation and saves it to a file. It can later be reloaded with LoadXml. This example builds a message and saves it as XML.

Background: This XML format is an alternative to the standard .eml (MIME) format for persisting an email. Note that .eml also preserves Chilkat's CKX- metadata headers (which are always removed before an email is sent), so it captures the same information. Because .eml is universal and interoperable, Chilkat recommends using SaveEml / LoadEml over the XML format — even within Chilkat-based software.

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    // Demonstrates the SaveXml method, which converts the email object to Chilkat's XML
    // representation and saves it to a file.  It can later be reloaded with LoadXml.

    const email = try chilkat.Email.init();
    defer email.deinit();
    email.setSubject("Save as XML");
    email.setFrom("alice@example.com");
    email.addTo("Bob", "bob@example.com") catch {};
    email.setBody("Hello!");

    // Save the email to a Chilkat XML file.
    email.saveXml("qa_output/email.xml") catch {
        std.debug.print("{s}\n", .{try email.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("Saved to email.xml.\n", .{});

    // Note: The path "qa_output/..." is a relative local filesystem path,
    // relative to the current working directory of the running application.
}