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
(PowerBuilder) 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.
integer li_rc oleobject loo_Imap integer li_Success oleobject loo_Secrets oleobject loo_Json string ls_Password oleobject loo_MessageSet integer li_Uid oleobject loo_Email oleobject loo_Cert loo_Imap = create oleobject // Use "Chilkat_9_5_0.Imap" for versions of Chilkat < 10.0.0 li_rc = loo_Imap.ConnectToNewObject("Chilkat.Imap") if li_rc < 0 then destroy loo_Imap MessageBox("Error","Connecting to COM object failed") return end if loo_Imap.Ssl = 1 loo_Imap.Port = 993 li_Success = loo_Imap.Connect("imap.example2.com") if li_Success <> 1 then Write-Debug loo_Imap.LastErrorText destroy loo_Imap 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 loo_Secrets = create oleobject // Use "Chilkat_9_5_0.Secrets" for versions of Chilkat < 10.0.0 li_rc = loo_Secrets.ConnectToNewObject("Chilkat.Secrets") // On Windows, this is the Windows Credentials Manager // On MacOS/iOS, it is the Apple Keychain loo_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. loo_Json = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject") loo_Json.UpdateString("appName","MyEmailApp") loo_Json.UpdateString("service","IMAP") loo_Json.UpdateString("domain","example2.com") loo_Json.UpdateString("username","jane@example2.com") ls_Password = loo_Secrets.GetSecretStr(loo_Json) if loo_Secrets.LastMethodSuccess = 0 then Write-Debug loo_Secrets.LastErrorText destroy loo_Imap destroy loo_Secrets destroy loo_Json return end if li_Success = loo_Imap.Login("jane@example2.com",ls_Password) if li_Success <> 1 then Write-Debug loo_Imap.LastErrorText destroy loo_Imap destroy loo_Secrets destroy loo_Json return end if // Select an IMAP mailbox li_Success = loo_Imap.SelectMailbox("Inbox") if li_Success <> 1 then Write-Debug loo_Imap.LastErrorText destroy loo_Imap destroy loo_Secrets destroy loo_Json 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. loo_MessageSet = loo_Imap.Search("SUBJECT encrypted",1) if loo_Imap.LastMethodSuccess = 0 then Write-Debug loo_Imap.LastErrorText destroy loo_Imap destroy loo_Secrets destroy loo_Json return end if if loo_MessageSet.Count = 0 then Write-Debug "No messages found." destroy loo_MessageSet destroy loo_Imap destroy loo_Secrets destroy loo_Json 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. li_Uid = loo_MessageSet.GetId(0) loo_Email = loo_Imap.FetchSingle(li_Uid,1) if loo_Imap.LastMethodSuccess = 0 then Write-Debug loo_Imap.LastErrorText destroy loo_MessageSet destroy loo_Imap destroy loo_Secrets destroy loo_Json 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. Write-Debug "Email received encrypted: " + string(loo_Email.ReceivedEncrypted) // Was it successfully decrypted? Write-Debug "Successfully decrypted: " + string(loo_Email.Decrypted) // What cert was used to decrypt? Write-Debug "Encrypted by: " + loo_Email.EncryptedBy loo_Cert = loo_Email.GetEncryptedByCert() if loo_Email.LastMethodSuccess = 1 then Write-Debug "Certificate DN: " + loo_Cert.SubjectDN destroy loo_Cert end if // Show the decrypted email body. Write-Debug loo_Email.Body destroy loo_MessageSet destroy loo_Email loo_Imap.Disconnect() destroy loo_Imap destroy loo_Secrets destroy loo_Json |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.