Lua Requires Chilkat v11.0.0+
Lua
Read Gmail POP3 Mailbox
Reads the header for each email in a GMail POP3 mailbox and displays the FROM and SUBJECT header fields. In your GMail "Forwarding and POP" settings, be sure to select "When messages are accessed with POP keep Gmail's copy in the Inbox".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 GMail account POP3 properties.
mailman.mail_host = "pop.gmail.com"
mailman.pop_username = "myLogin"
mailman.pop_password = "myPassword"
mailman.pop_ssl = true
mailman.mail_port = 995
-- Read mail headers and one line of the body.
-- To get the full emails, set headersOnly = false
local bundle = chilkat.EmailBundle.new()
local keepOnServer = true
local headersOnly = true
local numBodyLines = 1
local success = mailman:fetch_all(keepOnServer, headersOnly, numBodyLines, bundle)
if not success then
print(mailman.last_error_text)
return
end
local i = 0
local email = chilkat.Email.new()
while i < bundle.message_count do
bundle:email_at(i, email)
-- Display the From email address and the subject.
print("From: " .. email.from)
print("Subject: " .. email.subject)
i = i + 1
end