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

Read an attached email

See more Email Object Examples

Open forward-as-attachment.eml from the forwarding example. Read the cover note’s subject, then open each attached message and inspect its own headers and attachment count. This works even when the outer message has no ordinary files.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- Assumes Chilkat is unlocked. See Global Unlock Sample.

local wrapper = chilkat.Email.new()
local success = wrapper:load_eml("forward-as-attachment.eml")
if not success then
    print(wrapper.last_error_text)
    return
end

print("Cover note: " .. wrapper.subject)
if wrapper.num_attached_messages == 0 then
    print("No attached messages.")
    return
end

local nested = chilkat.Email.new()
local i = 0
while i < wrapper.num_attached_messages do
    success = wrapper:get_attached_email(i, nested)
    if not success then
        print(wrapper.last_error_text)
        return
    end

    print("Original author: " .. nested.from)
    print("Original subject: " .. nested.subject)
    print("Files on the original: " .. nested.num_attachments)
    i = i + 1
end