Zig
Zig
Upload .eml File to an IMAP Mailbox
See more IMAP Examples
Demonstrates how to upload the MIME source of an email to a mailbox on an IMAP server.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
const imap = try chilkat.Imap.init();
defer imap.deinit();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// Connect to an IMAP server.
// Use TLS
imap.setSsl(true);
imap.setPort(993);
imap.connect("MY-IMAP-DOMAIN") catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
// Login
imap.login("MY-IMAP-LOGIN", "MY-IMAP-PASSWORD") catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
const sb_mime = try chilkat.StringBuilder.init();
defer sb_mime.deinit();
sb_mime.loadFile("qa_data/eml/emoji_pizza.eml", "utf-8") catch {};
// Upload to the mailbox.
imap.appendMime("[Gmail]/testFolder", try sb_mime.getAsString(alloc)) catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
imap.disconnect() catch {};
std.debug.print("OK.\n", .{});
}