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

Process Large POP3 Mailbox

Demonstrates how to read email from a mailbox that may contain a large number of emails.

Chilkat Lua Downloads

Lua

    -- In the following call to loadlib, change the path (./chilkat.dll) to the relative or absolute directory where the chilkat.dll, chilkat.so, or chilkat.dylib is located.
    chilkat = assert(package.loadlib("./chilkat.dll", "luaopen_chilkat"))()
    print(chilkat._VERSION)

    local success = false

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

    local mailman = chilkat.newMailMan{}

    mailman:setMailHost("pop.example.com")

    mailman:setPopUsername("myLogin")
    mailman:setPopPassword("myPassword")

    mailman:setMailPort(995)
    mailman:setPopSsl(true)

    --  Get the list of UIDLs for all emails in the mailbox.
    local stUidls = chilkat.newStringTable{}
    success = mailman:FetchUidls(stUidls)
    if success == false then
        print(mailman:LastErrorText())

    end

    --  Download each email by UIDL.
    local email = chilkat.newEmail{}

    local count = stUidls:Count()
    local i = 0
    while i < count do
        --  Download the full email.
        local uidl = stUidls:StringAt(i)
        success = mailman:FetchByUidl(uidl,false,0,email)
        if success == false then
            print(mailman:LastErrorText())

        end

        print(i)
        print("UIDL: ", uidl)
        print("From: ", email:From())
        print("Subject: ", email:Subject())

        i = i + 1
    end

    mailman:Pop3EndSession()