Zig
Zig
Use a PFX TLS Client Certificate
See more SMTP Examples
Demonstrates the Chilkat MailMan.SetSslClientCertPfx method, which sets the client-side certificate for SSL/TLS connections, loading it from a PFX/PKCS#12 file. The first argument is the path to the PFX file and the second is its password. This example loads a client certificate directly from a PFX.
Background: This is the convenience form of
SetSslClientCert: rather than loading a Cert object first, you point straight at the PFX file and password. A PFX (PKCS#12) bundles the certificate with its private key — exactly what mutual TLS requires, since the client must prove possession of the key during the handshake. It is the usual client-credential format on Windows.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
var success: bool = false;
// Demonstrates the MailMan.SetSslClientCertPfx method, which sets the client-side
// certificate for SSL/TLS connections, loading it from a PFX/PKCS#12 file. The 1st argument
// is the PFX path and the 2nd is the PFX password.
const mailman = try chilkat.MailMan.init();
defer mailman.deinit();
// Configure the SMTP server connection.
mailman.setSmtpHost("smtp.example.com");
mailman.setSmtpPort(465);
mailman.setSmtpSsl(true);
mailman.setSmtpUsername("user@example.com");
mailman.setSmtpPassword("myPassword");
// Load the client certificate directly from a PFX file.
success = if (mailman.setSslClientCertPfx("qa_data/certs/client.pfx", "pfx_password")) true else |_| false;
if (!success) {
std.debug.print("{s}\n", .{try mailman.getLastErrorText(alloc)});
return;
}
success = mailman.verifySmtpLogin();
if (!success) {
std.debug.print("{s}\n", .{try mailman.getLastErrorText(alloc)});
return;
}
std.debug.print("Connected using a PFX TLS client certificate.\n", .{});
// Note: The path "qa_data/certs/client.pfx" is a relative local filesystem path,
// relative to the current working directory of the running application.
}