Sample code for 30+ languages & platforms
Zig

Send email using SMTP STARTTLS.

Send email using SMTP STARTTLS. With STARTTLS, the SMTP client connects to the SMTP server on port 25 (non-SSL) and then issues a STARTTLS command to convert the connection to a secure TLS channel.

Chilkat Zig Downloads

Zig
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 sending and receiving email.
    const mailman = try chilkat.MailMan.init();
    defer mailman.deinit();

    // Set the SMTP server.
    mailman.setSmtpHost("smtp.mymailserver.com");

    mailman.setSmtpUsername("myLogin");
    mailman.setSmtpPassword("myPassword");

    mailman.setStartTLS(true);

    // Create a new email object
    const email = try chilkat.Email.init();
    defer email.deinit();

    email.setSubject("This is a test");
    email.setBody("This is a test");
    email.setFrom("Chilkat Support <support@chilkatsoft.com>");
    try email.addTo("Chilkat Admin", "admin@chilkatsoft.com");

    mailman.sendEmail(email) catch {
        std.debug.print("{s}\n", .{try mailman.getLastErrorText(alloc)});
        return;
    };

    mailman.closeSmtpConnection() catch {
        std.debug.print("Connection to SMTP server not closed cleanly.\n", .{});
    };

    std.debug.print("Mail Sent!\n", .{});
}