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

POP3 Verify Signed (S/MIME) Email

Demonstrates how to download and verify digitally signed S/MIME email.

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.

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 cert = chilkat.Cert.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)

    -- The security layers of signed and/or encrypted emails
    -- are automatically "unwrapped" when loaded into
    -- a Chilkat email object.
    -- An application only needs to check to see if an email
    -- was received signed or encrypted, and then examine
    -- the success/failure.  For example:
    if email.received_signed then
        print("This email was signed.")

        -- Check to see if the signatures were verified.
        if email.signatures_valid then
            print("Digital signature(s) verified.")
            print("Signer: " .. email.signed_by)

            success = email:last_signer_cert(0, cert)
            if not success then
                print(email.last_error_text)
                return
            end

            print("Signing cert: " .. cert.subject_cn)
        end
    else
        print("Digital signature verification failed.")
    end

    i = i + 1
end

mailman:pop3_end_session()