Sample code for 30+ languages & platforms
Unicode C++

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 Unicode C++ Downloads

Unicode C++
#include <CkMimeW.h>
#include <CkCertW.h>

void ChilkatSample(void)
    {
    bool success = false;

    CkMimeW mime;
    success = mime.SetBodyFromPlainText(L"This message will be encrypted.");
    if (success == false) {
        wprintf(L"%s\n",mime.lastErrorText());
        return;
    }

    //  Add a recipient certificate.
    CkCertW cert;
    success = cert.LoadFromFile(L"qa_data/recipient.cer");
    if (success == false) {
        wprintf(L"%s\n",cert.lastErrorText());
        return;
    }

    success = mime.AddEncryptCert(cert);
    if (success == false) {
        wprintf(L"%s\n",mime.lastErrorText());
        return;
    }

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

    wprintf(L"Recipient certificate list cleared.\n");
    }