Sample code for 30+ languages & platforms
PowerShell

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

PowerShell
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"

$success = $false

$mime = New-Object Chilkat.Mime
$success = $mime.SetBodyFromPlainText("This message will be encrypted.")
if ($success -eq $false) {
    $($mime.LastErrorText)
    exit
}

#  Add a recipient certificate.
$cert = New-Object Chilkat.Cert
$success = $cert.LoadFromFile("qa_data/recipient.cer")
if ($success -eq $false) {
    $($cert.LastErrorText)
    exit
}

$success = $mime.AddEncryptCert($cert)
if ($success -eq $false) {
    $($mime.LastErrorText)
    exit
}

#  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.
$mime.ClearEncryptCerts()

$("Recipient certificate list cleared.")