Sample code for 30+ languages & platforms
Zig

Append a Part to a Multipart MIME Entity

See more MIME Examples

Demonstrates the Chilkat Mime.AppendPart method, which appends a copy of another Mime as the last direct child. The only argument is the source Mime. Chilkat copies it, so later changes to the source do not affect the appended part.

Background: This is the general way to build up a multipart entity from parts you construct yourself — a text body, an HTML body, a nested multipart. Because it appends a copy, you can reuse and modify the source object afterward, or append it more than once, without surprises. For attaching a file directly, AppendPartFromFile is more convenient.

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 Mime.AppendPart method, which appends a copy of another Mime as the last direct
    // child.  The only argument is the Mime to append.  Chilkat copies it, so later changes to the
    // source do not affect the appended part.

    const mime = try chilkat.Mime.init();
    defer mime.deinit();
    mime.newMultipartMixed() catch {
        std.debug.print("{s}\n", .{try mime.getLastErrorText(alloc)});
        return;
    };

    // Build a part and append a copy of it.
    const part = try chilkat.Mime.init();
    defer part.deinit();
    part.setBodyFromPlainText("This is an appended part.") catch {
        std.debug.print("{s}\n", .{try part.getLastErrorText(alloc)});
        return;
    };

    mime.appendPart(part) catch {
        std.debug.print("{s}\n", .{try mime.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("Number of parts: {d}\n", .{mime.getNumParts()});
}