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
(Lianja) 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.
loImap = createobject("CkImap") loImap.Ssl = .T. loImap.Port = 993 llSuccess = loImap.Connect("imap.example2.com") if (llSuccess <> .T.) then ? loImap.LastErrorText release loImap return endif // 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 loSecrets = createobject("CkSecrets") // On Windows, this is the Windows Credentials Manager // On MacOS/iOS, it is the Apple Keychain loSecrets.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. loJson = createobject("CkJsonObject") loJson.UpdateString("appName","MyEmailApp") loJson.UpdateString("service","IMAP") loJson.UpdateString("domain","example2.com") loJson.UpdateString("username","jane@example2.com") lcPassword = loSecrets.GetSecretStr(loJson) if (loSecrets.LastMethodSuccess = .F.) then ? loSecrets.LastErrorText release loImap release loSecrets release loJson return endif llSuccess = loImap.Login("jane@example2.com",lcPassword) if (llSuccess <> .T.) then ? loImap.LastErrorText release loImap release loSecrets release loJson return endif // Select an IMAP mailbox llSuccess = loImap.SelectMailbox("Inbox") if (llSuccess <> .T.) then ? loImap.LastErrorText release loImap release loSecrets release loJson return endif // 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. loMessageSet = loImap.Search("SUBJECT encrypted",.T.) if (loImap.LastMethodSuccess = .F.) then ? loImap.LastErrorText release loImap release loSecrets release loJson return endif if (loMessageSet.Count = 0) then ? "No messages found." release loMessageSet release loImap release loSecrets release loJson return endif // 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. lnUid = loMessageSet.GetId(0) loEmail = loImap.FetchSingle(lnUid,.T.) if (loImap.LastMethodSuccess = .F.) then ? loImap.LastErrorText release loMessageSet release loImap release loSecrets release loJson return endif // Here we can show if the email was received encrypted, if it was successfully decrypted, and // which certificate was used to decrypt. ? "Email received encrypted: " + str(loEmail.ReceivedEncrypted) // Was it successfully decrypted? ? "Successfully decrypted: " + str(loEmail.Decrypted) // What cert was used to decrypt? ? "Encrypted by: " + loEmail.EncryptedBy loCert = loEmail.GetEncryptedByCert() if (loEmail.LastMethodSuccess = .T.) then ? "Certificate DN: " + loCert.SubjectDN release loCert endif // Show the decrypted email body. ? loEmail.Body release loMessageSet release loEmail loImap.Disconnect() release loImap release loSecrets release loJson |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.