Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Mailman

li_Success = 0

//  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.

loo_Mailman = create oleobject
li_rc = loo_Mailman.ConnectToNewObject("Chilkat.MailMan")
if li_rc < 0 then
    destroy loo_Mailman
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  Configure the SMTP server connection.
loo_Mailman.SmtpHost = "smtp.example.com"
loo_Mailman.SmtpPort = 465
loo_Mailman.SmtpSsl = 1
loo_Mailman.SmtpUsername = "user@example.com"
loo_Mailman.SmtpPassword = "myPassword"

//  Load the client certificate directly from a PFX file.
li_Success = loo_Mailman.SetSslClientCertPfx("qa_data/certs/client.pfx","pfx_password")
if li_Success = 0 then
    Write-Debug loo_Mailman.LastErrorText
    destroy loo_Mailman
    return
end if

li_Success = loo_Mailman.VerifySmtpLogin()
if li_Success = 0 then
    Write-Debug loo_Mailman.LastErrorText
    destroy loo_Mailman
    return
end if

Write-Debug "Connected using a PFX TLS client certificate."

//  Note: The path "qa_data/certs/client.pfx" is a relative local filesystem path,
//  relative to the current working directory of the running application.


destroy loo_Mailman