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

Access Attached Message (Embedded Email)

How to access an email embedded within another email (i.e. an attached message).

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local email = chilkat.Email.new()

-- Load an email from a .eml
local success = email:load_eml("embeddedEmail.eml")
if not success then
    print(email.last_error_text)
    return
end

-- Display how many attached emails are embedded within
-- this one:
local numAttached = email.num_attached_messages
print("numAttached = " .. numAttached)

-- Get the 1st attached message.
local email2 = chilkat.Email.new()
success = email:get_attached_email(0, email2)
if success then
    -- Display the subject, From, and a header field...
    print(email2.subject)
    print(email2.from)
    print(email2:get_header_field("X-SOMETHING"))
end