Sample code for 30+ languages & platforms
PowerBuilder

Clear the Encryption Certificates of an Email

See more Email Object Examples

Demonstrates the Chilkat Email.ClearEncryptCerts method, which clears the internal list of explicitly specified certificates used when sending encrypted email — the certificates previously added with AddEncryptCert or SetEncryptCert. This example adds a recipient certificate and then clears the list.

Background: When encrypting to multiple recipients you register each one's certificate with AddEncryptCert. If an Email object is reused for different sets of recipients, those registered certificates would otherwise persist. ClearEncryptCerts resets that list so the next encrypted message is protected for exactly the intended recipients — a useful safeguard against accidentally encrypting for a stale recipient.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Email
oleobject loo_Cert

li_Success = 0

//  Demonstrates the ClearEncryptCerts method, which clears the internal list of explicitly
//  specified certificates used for sending encrypted email (the certificates added by
//  AddEncryptCert / SetEncryptCert).

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

//  Add a recipient certificate 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

//  ...then clear all explicitly-specified encryption certificates.
loo_Email.ClearEncryptCerts()

Write-Debug "Cleared the explicitly-specified encryption certificates."

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