Sample code for 30+ languages & platforms
Tcl

Connecting to GMAIL using IMAP

Demonstrates how to connect to GMAIL using IMAP.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

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

set imap [new_CkImap]

# Turn on session logging:
CkImap_put_KeepSessionLog $imap 1

# Connect to GMail
# Use TLS
CkImap_put_Ssl $imap 1
CkImap_put_Port $imap 993
set success [CkImap_Connect $imap "imap.gmail.com"]
if {$success != 1} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    exit
}

# Login
# Your login is typically your GMail email address.
set success [CkImap_Login $imap "username@gmail.com" "myPassword"]
if {$success != 1} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    exit
}

# Select an IMAP mailbox
set success [CkImap_SelectMailbox $imap "Inbox"]
if {$success != 1} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    exit
}

# Show the session log.
puts [CkImap_sessionLog $imap]

# Disconnect from the IMAP server.
set success [CkImap_Disconnect $imap]

delete_CkImap $imap