PowerBuilder
PowerBuilder
Save Email Credentials in Apple Keychain or Windows Credentials Manager
See more Apple Keychain Examples
This example demonstrates how to save (or update) email credentials in the Apple Keychain.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Secrets
oleobject loo_Json
li_Success = 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Secrets = create oleobject
li_rc = loo_Secrets.ConnectToNewObject("Chilkat.Secrets")
if li_rc < 0 then
destroy loo_Secrets
MessageBox("Error","Connecting to COM object failed")
return
end if
// 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
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.UpdateString("appName","MyEmailApp")
loo_Json.UpdateString("service","SMTP")
loo_Json.UpdateString("domain","example.com")
loo_Json.UpdateString("username","joe@example.com")
// Create or update the secret.
// This secret is the SMTP password for the above email account.
li_Success = loo_Secrets.UpdateSecretStr(loo_Json,"joes_password")
if li_Success = 0 then
Write-Debug loo_Secrets.LastErrorText
destroy loo_Secrets
destroy loo_Json
return
end if
// Let's save the IMAP secret for an account we'll read using IMAP..
loo_Json.UpdateString("appName","MyEmailApp")
loo_Json.UpdateString("service","IMAP")
loo_Json.UpdateString("domain","example2.com")
loo_Json.UpdateString("username","jane@example2.com")
li_Success = loo_Secrets.UpdateSecretStr(loo_Json,"janes_password")
if li_Success = 0 then
Write-Debug loo_Secrets.LastErrorText
destroy loo_Secrets
destroy loo_Json
return
end if
Write-Debug "Success."
destroy loo_Secrets
destroy loo_Json