PowerBuilder
PowerBuilder
Use a TLS Client Certificate
See more SMTP Examples
Demonstrates the Chilkat MailMan.SetSslClientCert method, which sets the client-side certificate to use for SSL/TLS connections. This is typically not required — most SSL/TLS connections authenticate the server only. This example loads a client certificate from a PFX and uses it when connecting.
Background: In an ordinary TLS handshake only the server presents a certificate, and the client proves who it is later with a password. Mutual TLS adds a second leg: the client also presents a certificate, so it is authenticated cryptographically at the transport layer. Some corporate or high-security mail servers require this. Because the client must prove possession of the key, the certificate needs its private key — hence loading from a PFX.
Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Mailman
oleobject loo_Cert
li_Success = 0
// Demonstrates the MailMan.SetSslClientCert method, which sets the client-side certificate
// to use for SSL/TLS connections. This is typically not required -- most SSL/TLS
// connections authenticate the server only.
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 (with its private key) from a PFX file.
loo_Cert = create oleobject
li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert")
li_Success = loo_Cert.LoadPfxFile("qa_data/certs/client.pfx","pfx_password")
if li_Success = 0 then
Write-Debug loo_Cert.LastErrorText
destroy loo_Mailman
destroy loo_Cert
return
end if
// Use this certificate to identify the client during the TLS handshake.
li_Success = loo_Mailman.SetSslClientCert(loo_Cert)
if li_Success = 0 then
Write-Debug loo_Mailman.LastErrorText
destroy loo_Mailman
destroy loo_Cert
return
end if
li_Success = loo_Mailman.VerifySmtpLogin()
if li_Success = 0 then
Write-Debug loo_Mailman.LastErrorText
destroy loo_Mailman
destroy loo_Cert
return
end if
Write-Debug "Connected using a 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
destroy loo_Cert