Sample code for 30+ languages & platforms
AutoIt

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

AutoIt
Local $bSuccess = False

$oMime = ObjCreate("Chilkat.Mime")
$bSuccess = $oMime.SetBodyFromPlainText("This message will be encrypted.")
If ($bSuccess = False) Then
    ConsoleWrite($oMime.LastErrorText & @CRLF)
    Exit
EndIf

;  Add a recipient certificate.
$oCert = ObjCreate("Chilkat.Cert")
$bSuccess = $oCert.LoadFromFile("qa_data/recipient.cer")
If ($bSuccess = False) Then
    ConsoleWrite($oCert.LastErrorText & @CRLF)
    Exit
EndIf

$bSuccess = $oMime.AddEncryptCert($oCert)
If ($bSuccess = False) Then
    ConsoleWrite($oMime.LastErrorText & @CRLF)
    Exit
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 

ConsoleWrite("Recipient certificate list cleared." & @CRLF)