|  | 
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++) IMAP Read Encrypted EmailSee more IMAP ExamplesDemonstrates how to read encrypted email from an IMAP mailbox.Reading encrypted email works the same as reading non-encrypted email. If the required certificate and private key are available on the system (e.g., in the macOS Keychain or Windows Certificate Store), Chilkat will automatically locate them, decrypt the email, and handle the process seamlessly. Information about the original encrypted state of the email is available after it has been downloaded and decrypted. Note: This example requires Chilkat v11.0.0 or greater. 
 #include <CkImapW.h> #include <CkSecretsW.h> #include <CkJsonObjectW.h> #include <CkMessageSetW.h> #include <CkEmailW.h> #include <CkCertW.h> void ChilkatSample(void) { bool success = false; CkImapW imap; imap.put_Ssl(true); imap.put_Port(993); success = imap.Connect(L"imap.example2.com"); if (success == false) { wprintf(L"%s\n",imap.lastErrorText()); return; } // We'll get the IMAP email account's password from the Apple Keychain or Windows Credentials Manager. // See how we originally saved the email credentials to the Keychain here: // Save Email Credentials in Apple Keychain or Windows Credentials Manager CkSecretsW secrets; // On Windows, this is the Windows Credentials Manager // On MacOS/iOS, it is the Apple Keychain secrets.put_Location(L"local_manager"); // Specify the name of the secret. // service and username are required. // appName and domain are optional. // Note: The values are arbitrary and can be anything you want. CkJsonObjectW json; json.UpdateString(L"appName",L"MyEmailApp"); json.UpdateString(L"service",L"IMAP"); json.UpdateString(L"domain",L"example2.com"); json.UpdateString(L"username",L"jane@example2.com"); const wchar_t *password = secrets.getSecretStr(json); if (secrets.get_LastMethodSuccess() == false) { wprintf(L"%s\n",secrets.lastErrorText()); return; } success = imap.Login(L"jane@example2.com",password); if (success == false) { wprintf(L"%s\n",imap.lastErrorText()); return; } // Select an IMAP mailbox success = imap.SelectMailbox(L"Inbox"); if (success == false) { wprintf(L"%s\n",imap.lastErrorText()); return; } // This example: Send Encrypted Email using Certificate in Apple Keychain // sent an email with the subject "This email is encrypted". // Let's download an email with the word "encrypted" in the subject. CkMessageSetW messageSet; success = imap.QueryMbx(L"SUBJECT encrypted",true,messageSet); if (success == false) { wprintf(L"%s\n",imap.lastErrorText()); return; } if (messageSet.get_Count() == 0) { wprintf(L"No messages found.\n"); return; } // Reading encrypted email works the same as reading non-encrypted email. // If the required certificate and private key are available on the system (e.g., in the macOS Keychain or Windows Certificate Store), // Chilkat will automatically locate them, decrypt the email, and handle the process seamlessly. unsigned long uid = messageSet.GetId(0); CkEmailW email; success = imap.FetchEmail(false,uid,true,email); if (success == false) { wprintf(L"%s\n",imap.lastErrorText()); return; } // Here we can show if the email was received encrypted, if it was successfully decrypted, and // which certificate was used to decrypt. wprintf(L"Email received encrypted: %d\n",email.get_ReceivedEncrypted()); // Was it successfully decrypted? wprintf(L"Successfully decrypted: %d\n",email.get_Decrypted()); // What cert was used to decrypt? wprintf(L"Encrypted by: %s\n",email.encryptedBy()); CkCertW cert; success = email.LastDecryptCert(cert); if (success != false) { wprintf(L"Certificate DN: %s\n",cert.subjectDN()); } // Show the decrypted email body. wprintf(L"%s\n",email.body()); imap.Disconnect(); } | ||||||
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.