Lua Requires Chilkat v11.0.0+
Lua
Download POP3 Email to MIME
Download the email from a POP3 mailbox directly into MIME, without parsing into email objects.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.
-- 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"
-- First, get the complete set of UIDLs for the email in the POP3 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 as MIME.
-- If desired, the MIME can be loaded into an email object.
local bdMime = chilkat.BinData.new()
local email = chilkat.Email.new()
local count = stUidls.count
local i = 0
while i < count do
success = mailman:fetch_mime_bd(stUidls:string_at(i), bdMime)
if not success then
print(mailman.last_error_text)
return
end
email:set_from_mime_bd(bdMime)
print("From: " .. email.from)
print("Subject: " .. email.subject)
i = i + 1
end