Sample code for 30+ languages & platforms
Lua Requires Chilkat v11.0.0+

Find the "Sent" IMAP Mailbox

See more IMAP Examples

Find the "Sent" IMAP mailbox. Also finds the Junk and Trash mailboxes..

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()

imap.ssl = true
imap.port = 993
local success = imap:connect("imap.yourmailserver.com")
if not success then
    print(imap.last_error_text)
    return
end

-- Login or authenticate in some way..
success = imap:login("your_login", "your_password")
if not success then
    print(imap.last_error_text)
    return
end

-- Get the list of mailboxes.
local refName = ""
local wildcardedMailbox = "*"
local subscribed = false

local mboxes = chilkat.Mailboxes.new()
success = imap:mbx_list(subscribed, refName, wildcardedMailbox, mboxes)
if not success then
    print(imap.last_error_text)
    return
end

-- The mailbox with the "/Sent" flag is the "Sent" mailbox.
-- Likewise for Junk and Trash..
local i = 0
while i < mboxes.count do
    if mboxes:has_flag(i, "\\Sent") then
        print("Sent mailbox: " .. mboxes:get_name(i))
    end

    if mboxes:has_flag(i, "\\Junk") then
        print("Junk mailbox: " .. mboxes:get_name(i))
    end

    if mboxes:has_flag(i, "\\Trash") then
        print("Trash mailbox: " .. mboxes:get_name(i))
    end

    i = i + 1
end

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