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

POP3 STARTTLS

Demonstrates how to do POP3 STARTTLS.

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.gmail.com"

-- Set the POP3 login/password.
mailman.pop_username = "****@gmail.com"
mailman.pop_password = "****"

-- Indicate that we want TLS/SSL.  Also, set the port to 995:
mailman.mail_port = 995
mailman.pop_ssl = true

local bundle = chilkat.EmailBundle.new()
local keepOnServer = true
local headersOnly = false
-- Irrelevent because we are NOT downloading headers-only
local numBodyLines = 0
local success = mailman:fetch_all(keepOnServer, headersOnly, numBodyLines, bundle)
if not success then
    print(mailman.last_error_text)
    return
end

local email = chilkat.Email.new()
local i = 0
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