PowerBuilder
PowerBuilder
Specify a Certificate for Encrypted Email
See more Email Object Examples
Demonstrates the Chilkat Email.AddEncryptCert method, which explicitly specifies a certificate to use when sending encrypted email. Call it once per recipient certificate; ClearEncryptCerts clears the list. This example loads a recipient certificate, registers it, and enables encrypted sending.
Background: When encrypting to multiple people, each recipient needs to be able to decrypt with their own private key. S/MIME handles this by encrypting the message's one-time content key separately under each recipient's public certificate and including all of those wrapped keys in the message.
AddEncryptCert is how you build that recipient list — one call per certificate — giving explicit control over exactly whose certificates are used rather than relying on automatic lookup.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Email
oleobject loo_Cert
li_Success = 0
// Demonstrates the AddEncryptCert method, which explicitly specifies a certificate for
// sending encrypted email. Call it once per recipient certificate. Use ClearEncryptCerts
// to clear the list.
loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
if li_rc < 0 then
destroy loo_Email
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Email.Subject = "Encrypted email"
loo_Email.Body = "Encrypted to the specified recipient certificate(s)."
loo_Email.From = "alice@example.com"
loo_Email.AddTo("Bob","bob@example.com")
// Load a recipient certificate (public key) and add it to the encryption cert list.
loo_Cert = create oleobject
li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert")
li_Success = loo_Cert.LoadFromFile("qa_data/certs/recipient.cer")
if li_Success = 0 then
Write-Debug loo_Cert.LastErrorText
destroy loo_Email
destroy loo_Cert
return
end if
li_Success = loo_Email.AddEncryptCert(loo_Cert)
if li_Success = 0 then
Write-Debug loo_Email.LastErrorText
destroy loo_Email
destroy loo_Cert
return
end if
// Request encrypted sending.
loo_Email.SendEncrypted = 1
Write-Debug "Added the recipient's encryption certificate."
// Note: The path "qa_data/certs/recipient.cer" is a relative local filesystem path,
// relative to the current working directory of the running application.
destroy loo_Email
destroy loo_Cert