Sample code for 30+ languages & platforms
Visual FoxPro

Log In to an IMAP Server

See more IMAP Examples

Demonstrates the Chilkat Imap.Login method, which authenticates the connected IMAP session using a login name and password. Connect must be called first. This example connects, logs in, and disconnects.

Background: Authentication is a distinct step from connecting: after the TCP/TLS connection is up, Login sends the credentials so the server will grant access to the account's mailboxes. The exact mechanism (plain LOGIN, SASL, or OAuth2) depends on the server and the AuthMethod setting. For providers that require OAuth2 (such as Gmail and Outlook.com), the password is an access token rather than an account password.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loImap

lnSuccess = 0

*  Demonstrates the Imap.Login method, which authenticates the connected IMAP session using
*  a login name and password.  Call Connect first.

loImap = CreateObject('Chilkat.Imap')

loImap.Ssl = 1
loImap.Port = 993

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

*  Authenticate with the login name and password.
lnSuccess = loImap.Login("user@example.com","myPassword")
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    CANCEL
ENDIF

? "Logged in to the IMAP server."

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

RELEASE loImap