Sample code for 30+ languages & platforms
PowerBuilder

IMAP Login using SecureString Credentials

See more IMAP Examples

Demonstrates the Chilkat Imap.LoginSecure method, which authenticates a connected session using SecureString credentials. The first argument is the login name and the second is the password. This is the secure-string counterpart of Login; the mechanism is chosen by the AuthMethod property.

Background: A SecureString keeps the credential encrypted in memory and helps avoid leaving plaintext copies lying around in the process, which is why the password should come from an interactive prompt, an environment variable, or a secrets vault — never a hard-coded literal. For XOAUTH2, pass the login name in the first argument and the raw access token (without a Bearer prefix) in the second.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Imap
string ls_Password
oleobject loo_SecureLogin
oleobject loo_SecurePassword

li_Success = 0

//  Demonstrates the Imap.LoginSecure method, which authenticates the session using SecureString
//  credentials.  The 1st argument is the login name and the 2nd is the password.

loo_Imap = create oleobject
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.example.com")
if li_Success = 0 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    return
end if

//  The password is not hard-coded in source.  Insert code here to obtain it from an
//  interactive prompt, environment variable, or a secrets vault.

//  Place the login name and password into SecureString objects.
loo_SecureLogin = create oleobject
li_rc = loo_SecureLogin.ConnectToNewObject("Chilkat.SecureString")

loo_SecureLogin.Append("user@example.com")
loo_SecurePassword = create oleobject
li_rc = loo_SecurePassword.ConnectToNewObject("Chilkat.SecureString")

loo_SecurePassword.Append(ls_Password)

li_Success = loo_Imap.LoginSecure(loo_SecureLogin,loo_SecurePassword)
if li_Success = 0 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    destroy loo_SecureLogin
    destroy loo_SecurePassword
    return
end if

Write-Debug "Logged in securely."

li_Success = loo_Imap.Disconnect()
if li_Success = 0 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    destroy loo_SecureLogin
    destroy loo_SecurePassword
    return
end if



destroy loo_Imap
destroy loo_SecureLogin
destroy loo_SecurePassword