Zig Requires Chilkat v11.0.0+
Zig
POP3 STARTTLS
Demonstrates how to do POP3 STARTTLS.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 requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// The mailman object is used for receiving (POP3)
// and sending (SMTP) email.
const mailman = try chilkat.MailMan.init();
defer mailman.deinit();
// Set the POP3 server's hostname
mailman.setMailHost("pop.gmail.com");
// Set the POP3 login/password.
mailman.setPopUsername("****@gmail.com");
mailman.setPopPassword("****");
// Indicate that we want TLS/SSL. Also, set the port to 995:
mailman.setMailPort(995);
mailman.setPopSsl(true);
const bundle = try chilkat.EmailBundle.init();
defer bundle.deinit();
const keep_on_server = true;
const headers_only = false;
// Irrelevent because we are NOT downloading headers-only
const num_body_lines = 0;
mailman.fetchAll(keep_on_server, headers_only, num_body_lines, bundle) catch {
std.debug.print("{s}\n", .{try mailman.getLastErrorText(alloc)});
return;
};
const email = try chilkat.Email.init();
defer email.deinit();
var i: i32 = 0;
while (i < bundle.getMessageCount()) {
bundle.emailAt(i, email) catch {};
// Display the From email address and the subject.
std.debug.print("From: {s}\n", .{try email.getFrom(alloc)});
std.debug.print("Subject: {s}\n", .{try email.getSubject(alloc)});
i = i + 1;
}
}