Sample code for 30+ languages & platforms
Delphi DLL Requires Chilkat v11.0.0+

POP3 Verify Signed (S/MIME) Email

Demonstrates how to download and verify digitally signed S/MIME email.

Chilkat Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
mailman: HCkMailMan;
stUidls: HCkStringTable;
email: HCkEmail;
cert: HCkCert;
count: Integer;
i: Integer;

begin
success := False;

//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

mailman := CkMailMan_Create();

//  Set the POP3 server's hostname
CkMailMan_putMailHost(mailman,'pop.example.com');

//  Set the POP3 login/password.
CkMailMan_putPopUsername(mailman,'myLogin');
CkMailMan_putPopPassword(mailman,'myPassword');

stUidls := CkStringTable_Create();
success := CkMailMan_FetchUidls(mailman,stUidls);
if (success = False) then
  begin
    Memo1.Lines.Add(CkMailMan__lastErrorText(mailman));
    Exit;
  end;

email := CkEmail_Create();
cert := CkCert_Create();

count := CkStringTable_getCount(stUidls);
i := 0;
while i < count do
  begin
    //  Download the full email.
    success := CkMailMan_FetchByUidl(mailman,CkStringTable__stringAt(stUidls,i),False,0,email);
    if (success = False) then
      begin
        Memo1.Lines.Add(CkMailMan__lastErrorText(mailman));
        Exit;
      end;

    Memo1.Lines.Add(IntToStr(i));
    Memo1.Lines.Add('From: ' + CkEmail__from(email));
    Memo1.Lines.Add('Subject: ' + CkEmail__subject(email));

    //  The security layers of signed and/or encrypted emails
    //  are automatically "unwrapped" when loaded into
    //  a Chilkat email object.
    //  An application only needs to check to see if an email
    //  was received signed or encrypted, and then examine
    //  the success/failure.  For example:
    if (CkEmail_getReceivedSigned(email) = True) then
      begin

        Memo1.Lines.Add('This email was signed.');

        //  Check to see if the signatures were verified.
        if (CkEmail_getSignaturesValid(email) = True) then
          begin
            Memo1.Lines.Add('Digital signature(s) verified.');
            Memo1.Lines.Add('Signer: ' + CkEmail__signedBy(email));

            success := CkEmail_LastSignerCert(email,0,cert);
            if (success = False) then
              begin
                Memo1.Lines.Add(CkEmail__lastErrorText(email));
                Exit;
              end;

            Memo1.Lines.Add('Signing cert: ' + CkCert__subjectCN(cert));
          end;

      end
    else
      begin
        Memo1.Lines.Add('Digital signature verification failed.');
      end;

    i := i + 1;
  end;

CkMailMan_Pop3EndSession(mailman);

CkMailMan_Dispose(mailman);
CkStringTable_Dispose(stUidls);
CkEmail_Dispose(email);
CkCert_Dispose(cert);