PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Mailman
li_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.
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 from a PEM file.
li_Success = loo_Mailman.SetSslClientCertPem("qa_data/certs/client.pem","pem_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 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.
destroy loo_Mailman