Sample code for 30+ languages & platforms
Lua

Check the Last Known IMAP Connection State

See more IMAP Examples

Demonstrates the Chilkat Imap.IsConnected method, which returns the last known connection state without sending any data to the IMAP server. A true result does not prove that an idle connection is still usable. This example connects and reads the state.

Background: IsConnected is a cheap, cached check — it reports what Chilkat last observed without touching the network. That makes it fast, but it can be stale: a server or firewall may have silently dropped an idle connection. When you need to be sure the connection is actually alive, send a lightweight round trip such as Noop, or use CheckConnection for a low-level socket probe.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- Demonstrates the Imap.IsConnected method, which returns the last known connection state
-- without sending data to the IMAP server.  A true result does not prove that an idle
-- connection is still usable.

local imap = chilkat.Imap.new()

imap.ssl = true
imap.port = 993

local success = imap:connect("imap.example.com")
if not success then
    print(imap.last_error_text)
    return
end

-- Check the last known connection state (no data is sent to the server).
local connected = imap:is_connected()
if connected then
    print("The IMAP object believes it is connected.")
else
    print("The IMAP object is not connected.")
end

success = imap:disconnect()
if not success then
    print(imap.last_error_text)
    return
end