Sample code for 30+ languages & platforms
Zig

Create a multipart/mixed MIME Entity

See more MIME Examples

Demonstrates the Chilkat Mime.NewMultipartMixed method, which initializes the object as an empty multipart/mixed entity, clearing any existing content. It takes no arguments; child parts are then appended.

Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background: multipart/mixed is the container for independent parts shown one after another — the classic "message body plus attachments" layout. Each child is its own distinct content, unlike multipart/alternative (competing renderings of the same thing) or multipart/related (a part and its embedded resources). Start here, then AppendPart a body and AppendPartFromFile the attachments.

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.NewMultipartMixed method, which initializes the object as an empty
    // multipart/mixed entity, clearing any existing headers, body, and child parts.  It takes no
    // arguments.

    const mime = try chilkat.Mime.init();
    defer mime.deinit();

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

    // Append child parts.  multipart/mixed is the container for a message body plus attachments.
    const body_part = try chilkat.Mime.init();
    defer body_part.deinit();
    body_part.setBodyFromPlainText("See the attached report.") catch {
        std.debug.print("{s}\n", .{try body_part.getLastErrorText(alloc)});
        return;
    };

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

    mime.appendPartFromFile("qa_data/report.pdf") catch {
        std.debug.print("{s}\n", .{try mime.getLastErrorText(alloc)});
        return;
    };

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