Zig
Zig
Connecting to GMAIL using IMAP
Demonstrates how to connect to GMAIL using IMAP.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();
// Turn on session logging:
imap.setKeepSessionLog(true);
// Connect to GMail
// Use TLS
imap.setSsl(true);
imap.setPort(993);
imap.connect("imap.gmail.com") catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
// Login
// Your login is typically your GMail email address.
imap.login("username@gmail.com", "myPassword") catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
// Select an IMAP mailbox
imap.selectMailbox("Inbox") catch {
std.debug.print("{s}\n", .{try imap.getLastErrorText(alloc)});
return;
};
// Show the session log.
std.debug.print("{s}\n", .{try imap.getSessionLog(alloc)});
// Disconnect from the IMAP server.
try imap.disconnect();
}