Sample code for 30+ languages & platforms
Lua

Connecting to GMAIL using IMAP

Demonstrates how to connect to GMAIL using IMAP.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

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

local imap = chilkat.Imap.new()

-- Turn on session logging:
imap.keep_session_log = true

-- Connect to GMail
-- Use TLS
imap.ssl = true
imap.port = 993
local success = imap:connect("imap.gmail.com")
if not success then
    print(imap.last_error_text)
    return
end

-- Login
-- Your login is typically your GMail email address.
success = imap:login("username@gmail.com", "myPassword")
if not success then
    print(imap.last_error_text)
    return
end

-- Select an IMAP mailbox
success = imap:select_mailbox("Inbox")
if not success then
    print(imap.last_error_text)
    return
end

-- Show the session log.
print(imap.session_log)

-- Disconnect from the IMAP server.
success = imap:disconnect()