Sample code for 30+ languages & platforms
Xbase++

Clear the S/MIME Recipient Certificate List

See more MIME Examples

Demonstrates ClearEncryptCerts, which empties the recipient-certificate list previously populated by AddEncryptCert. This is useful to start over with a different set of recipients before calling EncryptN.

Background. The recipient list is internal state that accumulates across AddEncryptCert calls. ClearEncryptCerts resets it so a subsequent EncryptN encrypts only for the certificates added afterward.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oMime
LOCAL oCert

nSuccess := 0

oMime := CreateObject("Chilkat.Mime")
nSuccess := oMime:SetBodyFromPlainText("This message will be encrypted.")
IF (nSuccess == 0)
    ? oMime:LastErrorText
    oMime:destroy()
    RETURN
ENDIF

//  Add a recipient certificate.
oCert := CreateObject("Chilkat.Cert")
nSuccess := oCert:LoadFromFile("qa_data/recipient.cer")
IF (nSuccess == 0)
    ? oCert:LastErrorText
    oMime:destroy()
    oCert:destroy()
    RETURN
ENDIF

nSuccess := oMime:AddEncryptCert(oCert)
IF (nSuccess == 0)
    ? oMime:LastErrorText
    oMime:destroy()
    oCert:destroy()
    RETURN
ENDIF

//  ClearEncryptCerts empties the recipient-certificate list, for example to start over with a
//  different set of recipients before calling EncryptN.  It is a void method.
oMime:ClearEncryptCerts()

? "Recipient certificate list cleared."

oMime:destroy()
oCert:destroy()