Zig Requires Chilkat v11.0.0+
Zig
Read Gmail POP3 Mailbox
Reads the header for each email in a GMail POP3 mailbox and displays the FROM and SUBJECT header fields. In your GMail "Forwarding and POP" settings, be sure to select "When messages are accessed with POP keep Gmail's copy in the Inbox".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 GMail account POP3 properties.
mailman.setMailHost("pop.gmail.com");
mailman.setPopUsername("myLogin");
mailman.setPopPassword("myPassword");
mailman.setPopSsl(true);
mailman.setMailPort(995);
// Read mail headers and one line of the body.
// To get the full emails, set headersOnly = false
const bundle = try chilkat.EmailBundle.init();
defer bundle.deinit();
const keep_on_server = true;
const headers_only = true;
const num_body_lines = 1;
mailman.fetchAll(keep_on_server, headers_only, num_body_lines, bundle) catch {
std.debug.print("{s}\n", .{try mailman.getLastErrorText(alloc)});
return;
};
var i: i32 = 0;
const email = try chilkat.Email.init();
defer email.deinit();
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;
}
}