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
(Go) 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.
imap := chilkat.NewImap() imap.SetSsl(true) imap.SetPort(993) success := imap.Connect("imap.example2.com") if success != true { fmt.Println(imap.LastErrorText()) imap.DisposeImap() 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 secrets := chilkat.NewSecrets() // On Windows, this is the Windows Credentials Manager // On MacOS/iOS, it is the Apple Keychain secrets.SetLocation("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. json := chilkat.NewJsonObject() json.UpdateString("appName","MyEmailApp") json.UpdateString("service","IMAP") json.UpdateString("domain","example2.com") json.UpdateString("username","jane@example2.com") password := secrets.GetSecretStr(json) if secrets.LastMethodSuccess() == false { fmt.Println(secrets.LastErrorText()) imap.DisposeImap() secrets.DisposeSecrets() json.DisposeJsonObject() return } success = imap.Login("jane@example2.com",*password) if success != true { fmt.Println(imap.LastErrorText()) imap.DisposeImap() secrets.DisposeSecrets() json.DisposeJsonObject() return } // Select an IMAP mailbox success = imap.SelectMailbox("Inbox") if success != true { fmt.Println(imap.LastErrorText()) imap.DisposeImap() secrets.DisposeSecrets() json.DisposeJsonObject() 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. messageSet := imap.Search("SUBJECT encrypted",true) if imap.LastMethodSuccess() == false { fmt.Println(imap.LastErrorText()) imap.DisposeImap() secrets.DisposeSecrets() json.DisposeJsonObject() return } if messageSet.Count() == 0 { fmt.Println("No messages found.") messageSet.DisposeMessageSet() imap.DisposeImap() secrets.DisposeSecrets() json.DisposeJsonObject() 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. uid := messageSet.GetId(0) email := imap.FetchSingle(uid,true) if imap.LastMethodSuccess() == false { fmt.Println(imap.LastErrorText()) messageSet.DisposeMessageSet() imap.DisposeImap() secrets.DisposeSecrets() json.DisposeJsonObject() return } // Here we can show if the email was received encrypted, if it was successfully decrypted, and // which certificate was used to decrypt. fmt.Println("Email received encrypted: ", email.ReceivedEncrypted()) // Was it successfully decrypted? fmt.Println("Successfully decrypted: ", email.Decrypted()) // What cert was used to decrypt? fmt.Println("Encrypted by: ", email.EncryptedBy()) cert := email.GetEncryptedByCert() if email.LastMethodSuccess() == true { fmt.Println("Certificate DN: ", cert.SubjectDN()) cert.DisposeCert() } // Show the decrypted email body. fmt.Println(email.Body()) messageSet.DisposeMessageSet() email.DisposeEmail() imap.Disconnect() imap.DisposeImap() secrets.DisposeSecrets() json.DisposeJsonObject() |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.