![]() |
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
(Unicode 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_CkMailManW.h> #include <C_CkStringTableW.h> #include <C_CkEmailW.h> #include <C_CkCertW.h> void ChilkatSample(void) { BOOL success; HCkMailManW mailman; HCkStringTableW stUidls; HCkEmailW email; HCkCertW 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 = CkMailManW_Create(); // Set the POP3 server's hostname CkMailManW_putMailHost(mailman,L"pop.example.com"); // Set the POP3 login/password. CkMailManW_putPopUsername(mailman,L"myLogin"); CkMailManW_putPopPassword(mailman,L"myPassword"); stUidls = CkStringTableW_Create(); success = CkMailManW_FetchUidls(mailman,stUidls); if (success == FALSE) { wprintf(L"%s\n",CkMailManW_lastErrorText(mailman)); CkMailManW_Dispose(mailman); CkStringTableW_Dispose(stUidls); return; } email = CkEmailW_Create(); cert = CkCertW_Create(); count = CkStringTableW_getCount(stUidls); i = 0; while (i < count) { // Download the full email. success = CkMailManW_FetchByUidl(mailman,CkStringTableW_stringAt(stUidls,i),FALSE,0,email); if (success == FALSE) { wprintf(L"%s\n",CkMailManW_lastErrorText(mailman)); CkMailManW_Dispose(mailman); CkStringTableW_Dispose(stUidls); CkEmailW_Dispose(email); CkCertW_Dispose(cert); return; } wprintf(L"%d\n",i); wprintf(L"From: %s\n",CkEmailW_ck_from(email)); wprintf(L"Subject: %s\n",CkEmailW_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 (CkEmailW_getReceivedSigned(email) == TRUE) { wprintf(L"This email was signed.\n"); // Check to see if the signatures were verified. if (CkEmailW_getSignaturesValid(email) == TRUE) { wprintf(L"Digital signature(s) verified.\n"); wprintf(L"Signer: %s\n",CkEmailW_signedBy(email)); success = CkEmailW_LastSignerCert(email,0,cert); if (success == FALSE) { wprintf(L"%s\n",CkEmailW_lastErrorText(email)); CkMailManW_Dispose(mailman); CkStringTableW_Dispose(stUidls); CkEmailW_Dispose(email); CkCertW_Dispose(cert); return; } wprintf(L"Signing cert: %s\n",CkCertW_subjectCN(cert)); } } else { wprintf(L"Digital signature verification failed.\n"); } i = i + 1; } CkMailManW_Pop3EndSession(mailman); CkMailManW_Dispose(mailman); CkStringTableW_Dispose(stUidls); CkEmailW_Dispose(email); CkCertW_Dispose(cert); } |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.