Tcl
Tcl
Use a PEM TLS Client Certificate
See more SMTP Examples
Demonstrates the Chilkat MailMan.SetSslClientCertPem method, which sets the client-side certificate for SSL/TLS connections, loading it from PEM data or from a PEM file. The first argument may contain the PEM text itself or a path to a PEM file; the second is the PEM password. This example loads the client certificate from a PEM file.
Background: PEM is the familiar Base64 text format bracketed by
-----BEGIN CERTIFICATE----- lines, and a single PEM can hold both a certificate and its (optionally encrypted) private key. It is the common format in Unix/OpenSSL environments, whereas PFX is more typical on Windows. Because this method accepts either the PEM text or a filename, you can supply credentials straight from a config value or secret store without writing them to disk.Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# Demonstrates the MailMan.SetSslClientCertPem method, which sets the client-side
# certificate for SSL/TLS connections, loading it from PEM data or from a PEM file. The
# 1st argument may contain PEM text or a PEM file path; the 2nd is the PEM password.
set mailman [new_CkMailMan]
# Configure the SMTP server connection.
CkMailMan_put_SmtpHost $mailman "smtp.example.com"
CkMailMan_put_SmtpPort $mailman 465
CkMailMan_put_SmtpSsl $mailman 1
CkMailMan_put_SmtpUsername $mailman "user@example.com"
CkMailMan_put_SmtpPassword $mailman "myPassword"
# Load the client certificate from a PEM file.
set success [CkMailMan_SetSslClientCertPem $mailman "qa_data/certs/client.pem" "pem_password"]
if {$success == 0} then {
puts [CkMailMan_lastErrorText $mailman]
delete_CkMailMan $mailman
exit
}
set success [CkMailMan_VerifySmtpLogin $mailman]
if {$success == 0} then {
puts [CkMailMan_lastErrorText $mailman]
delete_CkMailMan $mailman
exit
}
puts "Connected using a PEM TLS client certificate."
# Note: The path "qa_data/certs/client.pem" is a relative local filesystem path,
# relative to the current working directory of the running application.
delete_CkMailMan $mailman