Sample code for 30+ languages & platforms
Tcl

Check Whether the IMAP Session Is Authenticated

See more IMAP Examples

Demonstrates the Chilkat Imap.IsLoggedIn method, which indicates whether this object is in an authenticated IMAP session. It reports the last known state and does not send a command to the server. This example connects, logs in, and checks the state.

Background: An IMAP session has two levels: connected (the TCP/TLS link is up) and authenticated (login succeeded). IsLoggedIn reports the second — useful when reusing a long-lived Imap object to decide whether you still need to log in before performing mailbox operations. Like IsConnected, it reflects cached state and doesn't contact the server.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

#  Demonstrates the Imap.IsLoggedIn method, which indicates whether this object is in an
#  authenticated IMAP session.  It reports the last known state and does not send a command
#  to the server.

set imap [new_CkImap]

CkImap_put_Ssl $imap 1
CkImap_put_Port $imap 993

set success [CkImap_Connect $imap "imap.example.com"]
if {$success == 0} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    exit
}

set success [CkImap_Login $imap "user@example.com" "myPassword"]
if {$success == 0} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    exit
}

#  Check whether the session is authenticated.
set loggedIn [CkImap_IsLoggedIn $imap]
if {$loggedIn == 1} then {
    puts "The session is authenticated."
} else {
    puts "The session is not authenticated."
}

set success [CkImap_Disconnect $imap]
if {$success == 0} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    exit
}


delete_CkImap $imap