Zig
Zig
Upload (Append) Email to an IMAP Mailbox
Upload / append an email to an IMAP mailbox.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const imap = try chilkat.Imap.init();
defer imap.deinit();
// Connect to an IMAP server.
// Use TLS
imap.setSsl(true);
imap.setPort(993);
imap.connect("imap.example.com") catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
// Login
imap.login("myLogin", "myPassword") catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
const email = try chilkat.Email.init();
defer email.deinit();
// Load the email from a .eml file.
email.loadEml("myEmail.eml") catch {
std.debug.print("{s}\n", .{try email.getLastErrorText(alloc)});
return;
};
imap.appendMail("Inbox", email) catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
std.debug.print("Email uploaded to Inbox!\n", .{});
// Disconnect from the IMAP server.
try imap.disconnect();
}