Sample code for 30+ languages & platforms
Delphi DLL

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 Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
mime: HCkMime;
cert: HCkCert;

begin
success := False;

mime := CkMime_Create();
success := CkMime_SetBodyFromPlainText(mime,'This message will be encrypted.');
if (success = False) then
  begin
    Memo1.Lines.Add(CkMime__lastErrorText(mime));
    Exit;
  end;

//  Add a recipient certificate.
cert := CkCert_Create();
success := CkCert_LoadFromFile(cert,'qa_data/recipient.cer');
if (success = False) then
  begin
    Memo1.Lines.Add(CkCert__lastErrorText(cert));
    Exit;
  end;
success := CkMime_AddEncryptCert(mime,cert);
if (success = False) then
  begin
    Memo1.Lines.Add(CkMime__lastErrorText(mime));
    Exit;
  end;

//  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.
CkMime_ClearEncryptCerts(mime);

Memo1.Lines.Add('Recipient certificate list cleared.');

CkMime_Dispose(mime);
CkCert_Dispose(cert);