Sample code for 30+ languages & platforms
DataFlex

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

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoEmail
    Variant vCert
    Handle hoCert
    String sTemp1

    Move False To iSuccess

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

    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End

    //  Add a recipient certificate to the encryption cert list...
    Get Create (RefClass(cComChilkatCert)) To hoCert
    If (Not(IsComObjectCreated(hoCert))) Begin
        Send CreateComObject of hoCert
    End
    Get ComLoadFromFile Of hoCert "qa_data/certs/recipient.cer" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoCert To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get pvComObject of hoCert to vCert
    Get ComAddEncryptCert Of hoEmail vCert To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoEmail To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  ...then clear all explicitly-specified encryption certificates.
    Send ComClearEncryptCerts To hoEmail

    Showln "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.


End_Procedure