Sample code for 30+ languages & platforms
Zig Requires Chilkat v11.0.0+

Example: Email.GetDsnInfo method

See more Email Object Examples

Demonstrates how to call the GetDsnInfo method.

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();

    const email = try chilkat.Email.init();
    defer email.deinit();

    email.loadEml("qa_data/eml/sample_multipart_report.eml") catch {
        std.debug.print("{s}\n", .{try email.getLastErrorText(alloc)});
        return;
    };

    const json = try chilkat.JsonObject.init();
    defer json.deinit();
    email.getDsnInfo(json) catch {
        std.debug.print("{s}\n", .{try email.getLastErrorText(alloc)});
        return;
    };

    json.setEmitCompact(false);
    std.debug.print("{s}\n", .{try json.emit(alloc)});

    // Sample output:

    // {
    //   "reporting-mta": "dns; Exchange2016.example.com",
    //   "final-recipient": [
    //     "herb.butterworth1247692846@gmail.com"
    //   ],
    //   "action": "failed",
    //   "status": "5.1.1",
    //   "remote-mta": "dns; mx.google.com",
    //   "x-supplementary-info": "<mx.google.com #5.1.1 smtp;550-5.1.1 The email account that you tried to reach does not exist. Please try 550-5.1.1 double-checking the recipient's email address for typos or 550-5.1.1 unnecessary spaces. Learn more at 550 5.1.1  https://support.google.com/mail/?p=NoSuchUser o8-20020a056870968800b001b55816bea9si2188132oaq.70 - gsmtp>",
    //   "x-display-name": "herb.butterworth1247692846@gmail.com"
    // }

    // Code for parsing the JSON:

    var str_val: [:0]const u8 = "";

    _ = try json.stringOf(alloc, "reporting-mta");
    _ = try json.stringOf(alloc, "action");
    _ = try json.stringOf(alloc, "status");
    _ = try json.stringOf(alloc, "remote-mta");
    _ = try json.stringOf(alloc, "x-supplementary-info");
    _ = try json.stringOf(alloc, "x-display-name");
    var i: i32 = 0;
    const count = json.sizeOfArray("final-recipient");
    while (i < count) {
        json.setI(i);
        str_val = try json.stringOf(alloc, "final-recipient[i]");
        i = i + 1;
    }
}