Lua Requires Chilkat v11.0.0+
Lua
Process Large POP3 Mailbox
Demonstrates how to read email from a mailbox that may contain a large number of emails.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local mailman = chilkat.MailMan.new()
mailman.mail_host = "pop.example.com"
mailman.pop_username = "myLogin"
mailman.pop_password = "myPassword"
mailman.mail_port = 995
mailman.pop_ssl = true
-- Get the list of UIDLs for all emails in the mailbox.
local stUidls = chilkat.StringTable.new()
local success = mailman:fetch_uidls(stUidls)
if not success then
print(mailman.last_error_text)
return
end
-- Download each email by UIDL.
local email = chilkat.Email.new()
local count = stUidls.count
local i = 0
while i < count do
-- Download the full email.
local uidl = stUidls:string_at(i)
success = mailman:fetch_by_uidl(uidl, false, 0, email)
if not success then
print(mailman.last_error_text)
return
end
print(i)
print("UIDL: " .. uidl)
print("From: " .. email.from)
print("Subject: " .. email.subject)
i = i + 1
end
mailman:pop3_end_session()