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
(Tcl) 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.
load ./chilkat.dll set imap [new_CkImap] CkImap_put_Ssl $imap 1 CkImap_put_Port $imap 993 set success [CkImap_Connect $imap "imap.example2.com"] if {$success != 1} then { puts [CkImap_lastErrorText $imap] delete_CkImap $imap exit } # 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 set secrets [new_CkSecrets] # On Windows, this is the Windows Credentials Manager # On MacOS/iOS, it is the Apple Keychain CkSecrets_put_Location $secrets "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. set json [new_CkJsonObject] CkJsonObject_UpdateString $json "appName" "MyEmailApp" CkJsonObject_UpdateString $json "service" "IMAP" CkJsonObject_UpdateString $json "domain" "example2.com" CkJsonObject_UpdateString $json "username" "jane@example2.com" set password [CkSecrets_getSecretStr $secrets $json] if {[CkSecrets_get_LastMethodSuccess $secrets] == 0} then { puts [CkSecrets_lastErrorText $secrets] delete_CkImap $imap delete_CkSecrets $secrets delete_CkJsonObject $json exit } set success [CkImap_Login $imap "jane@example2.com" $password] if {$success != 1} then { puts [CkImap_lastErrorText $imap] delete_CkImap $imap delete_CkSecrets $secrets delete_CkJsonObject $json exit } # Select an IMAP mailbox set success [CkImap_SelectMailbox $imap "Inbox"] if {$success != 1} then { puts [CkImap_lastErrorText $imap] delete_CkImap $imap delete_CkSecrets $secrets delete_CkJsonObject $json exit } # 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. # messageSet is a CkMessageSet set messageSet [CkImap_Search $imap "SUBJECT encrypted" 1] if {[CkImap_get_LastMethodSuccess $imap] == 0} then { puts [CkImap_lastErrorText $imap] delete_CkImap $imap delete_CkSecrets $secrets delete_CkJsonObject $json exit } if {[CkMessageSet_get_Count $messageSet] == 0} then { puts "No messages found." delete_CkMessageSet $messageSet delete_CkImap $imap delete_CkSecrets $secrets delete_CkJsonObject $json exit } # 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. set uid [CkMessageSet_GetId $messageSet 0] # email is a CkEmail set email [CkImap_FetchSingle $imap $uid 1] if {[CkImap_get_LastMethodSuccess $imap] == 0} then { puts [CkImap_lastErrorText $imap] delete_CkMessageSet $messageSet delete_CkImap $imap delete_CkSecrets $secrets delete_CkJsonObject $json exit } # Here we can show if the email was received encrypted, if it was successfully decrypted, and # which certificate was used to decrypt. puts "Email received encrypted: [CkEmail_get_ReceivedEncrypted $email]" # Was it successfully decrypted? puts "Successfully decrypted: [CkEmail_get_Decrypted $email]" # What cert was used to decrypt? puts "Encrypted by: [CkEmail_encryptedBy $email]" # cert is a CkCert set cert [CkEmail_GetEncryptedByCert $email] if {[CkEmail_get_LastMethodSuccess $email] == 1} then { puts "Certificate DN: [CkCert_subjectDN $cert]" delete_CkCert $cert } # Show the decrypted email body. puts [CkEmail_body $email] delete_CkMessageSet $messageSet delete_CkEmail $email CkImap_Disconnect $imap delete_CkImap $imap delete_CkSecrets $secrets delete_CkJsonObject $json |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.