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

Download POP3 Email using UIDLs

Demonstrates how to download POP3 email by first getting the complete set of UIDLs and then downloading email by calling FetchByUIDL for each UIDL.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

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

-- The mailman object is used for receiving (POP3)
-- and sending (SMTP) email.
local mailman = chilkat.MailMan.new()

-- Set the POP3 server's hostname
mailman.mail_host = "pop.example.com"

-- Set the POP3 login/password.
mailman.pop_username = "myLogin"
mailman.pop_password = "myPassword"

local stUidls = chilkat.StringTable.new()
local success = mailman:fetch_uidls(stUidls)
if not success then
    print(mailman.last_error_text)
    return
end

local email = chilkat.Email.new()

local count = stUidls.count
local i = 0
while i < count do
    -- Download the full email.
    success = mailman:fetch_by_uidl(stUidls:string_at(i), false, 0, email)
    if not success then
        print(mailman.last_error_text)
        return
    end

    print(i)
    print("From: " .. email.from)
    print("Subject: " .. email.subject)

    i = i + 1
end

mailman:pop3_end_session()