Sample code for 30+ languages & platforms
Lianja

Connecting to GMAIL using IMAP

Demonstrates how to connect to GMAIL using IMAP.

Chilkat Lianja Downloads

Lianja
llSuccess = .F.

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loImap = createobject("CkImap")

// Turn on session logging:
loImap.KeepSessionLog = .T.

// Connect to GMail
// Use TLS
loImap.Ssl = .T.
loImap.Port = 993
llSuccess = loImap.Connect("imap.gmail.com")
if (llSuccess <> .T.) then
    ? loImap.LastErrorText
    release loImap
    return
endif

// Login
// Your login is typically your GMail email address.
llSuccess = loImap.Login("username@gmail.com","myPassword")
if (llSuccess <> .T.) then
    ? loImap.LastErrorText
    release loImap
    return
endif

// Select an IMAP mailbox
llSuccess = loImap.SelectMailbox("Inbox")
if (llSuccess <> .T.) then
    ? loImap.LastErrorText
    release loImap
    return
endif

// Show the session log.
? loImap.SessionLog

// Disconnect from the IMAP server.
llSuccess = loImap.Disconnect()


release loImap