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
(Xojo Plugin) 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 v10.1.2 or later because it uses the Secrets class.
Dim imap As New Chilkat.Imap imap.Ssl = True imap.Port = 993 Dim success As Boolean success = imap.Connect("imap.example2.com") If (success <> True) Then System.DebugLog(imap.LastErrorText) Return End If // 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 Dim secrets As New Chilkat.Secrets // On Windows, this is the Windows Credentials Manager // On MacOS/iOS, it is the Apple Keychain secrets.Location = "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. Dim json As New Chilkat.JsonObject success = json.UpdateString("appName","MyEmailApp") success = json.UpdateString("service","IMAP") success = json.UpdateString("domain","example2.com") success = json.UpdateString("username","jane@example2.com") Dim password As String password = secrets.GetSecretStr(json) If (secrets.LastMethodSuccess = False) Then System.DebugLog(secrets.LastErrorText) Return End If success = imap.Login("jane@example2.com",password) If (success <> True) Then System.DebugLog(imap.LastErrorText) Return End If // Select an IMAP mailbox success = imap.SelectMailbox("Inbox") If (success <> True) Then System.DebugLog(imap.LastErrorText) Return End If // 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. Dim messageSet As Chilkat.MessageSet messageSet = imap.Search("SUBJECT encrypted",True) If (imap.LastMethodSuccess = False) Then System.DebugLog(imap.LastErrorText) Return End If If (messageSet.Count = 0) Then System.DebugLog("No messages found.") Return End If // 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. Dim uid As UInt32 uid = messageSet.GetId(0) Dim email As Chilkat.Email email = imap.FetchSingle(uid,True) If (imap.LastMethodSuccess = False) Then System.DebugLog(imap.LastErrorText) Return End If // Here we can show if the email was received encrypted, if it was successfully decrypted, and // which certificate was used to decrypt. System.DebugLog("Email received encrypted: " + Str(email.ReceivedEncrypted)) // Was it successfully decrypted? System.DebugLog("Successfully decrypted: " + Str(email.Decrypted)) // What cert was used to decrypt? System.DebugLog("Encrypted by: " + email.EncryptedBy) Dim cert As Chilkat.Cert cert = email.GetEncryptedByCert() If (email.LastMethodSuccess = True) Then System.DebugLog("Certificate DN: " + cert.SubjectDN) End If // Show the decrypted email body. System.DebugLog(email.Body) success = imap.Disconnect() |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.