Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loImap
LOCAL lcPassword
LOCAL loSecureLogin
LOCAL loSecurePassword

lnSuccess = 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.

loImap = CreateObject('Chilkat.Imap')

loImap.Ssl = 1
loImap.Port = 993

lnSuccess = loImap.Connect("imap.example.com")
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    CANCEL
ENDIF

*  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.
loSecureLogin = CreateObject('Chilkat.SecureString')
loSecureLogin.Append("user@example.com")
loSecurePassword = CreateObject('Chilkat.SecureString')
loSecurePassword.Append(lcPassword)

lnSuccess = loImap.LoginSecure(loSecureLogin,loSecurePassword)
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    RELEASE loSecureLogin
    RELEASE loSecurePassword
    CANCEL
ENDIF

? "Logged in securely."

lnSuccess = loImap.Disconnect()
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    RELEASE loSecureLogin
    RELEASE loSecurePassword
    CANCEL
ENDIF

RELEASE loImap
RELEASE loSecureLogin
RELEASE loSecurePassword