![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(C) POP3 Verify Signed (S/MIME) EmailDemonstrates how to download and verify digitally signed S/MIME email. Note: This example requires Chilkat v11.0.0 or greater.
#include <C_CkMailMan.h> #include <C_CkStringTable.h> #include <C_CkEmail.h> #include <C_CkCert.h> void ChilkatSample(void) { BOOL success; HCkMailMan mailman; HCkStringTable stUidls; HCkEmail email; HCkCert cert; int count; int i; 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) { printf("%s\n",CkMailMan_lastErrorText(mailman)); CkMailMan_Dispose(mailman); CkStringTable_Dispose(stUidls); return; } email = CkEmail_Create(); cert = CkCert_Create(); count = CkStringTable_getCount(stUidls); i = 0; while (i < count) { // Download the full email. success = CkMailMan_FetchByUidl(mailman,CkStringTable_stringAt(stUidls,i),FALSE,0,email); if (success == FALSE) { printf("%s\n",CkMailMan_lastErrorText(mailman)); CkMailMan_Dispose(mailman); CkStringTable_Dispose(stUidls); CkEmail_Dispose(email); CkCert_Dispose(cert); return; } printf("%d\n",i); printf("From: %s\n",CkEmail_ck_from(email)); printf("Subject: %s\n",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) { printf("This email was signed.\n"); // Check to see if the signatures were verified. if (CkEmail_getSignaturesValid(email) == TRUE) { printf("Digital signature(s) verified.\n"); printf("Signer: %s\n",CkEmail_signedBy(email)); success = CkEmail_LastSignerCert(email,0,cert); if (success == FALSE) { printf("%s\n",CkEmail_lastErrorText(email)); CkMailMan_Dispose(mailman); CkStringTable_Dispose(stUidls); CkEmail_Dispose(email); CkCert_Dispose(cert); return; } printf("Signing cert: %s\n",CkCert_subjectCN(cert)); } } else { printf("Digital signature verification failed.\n"); } i = i + 1; } CkMailMan_Pop3EndSession(mailman); CkMailMan_Dispose(mailman); CkStringTable_Dispose(stUidls); CkEmail_Dispose(email); CkCert_Dispose(cert); } |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.