Lua Requires Chilkat v11.0.0+
Lua
Read email headers and display the body as text
See more Email Object Examples
Read the sender, recipients, subject, date, and an optional custom header from an EML file. Display the plain-text body when available, or convert HTML to text. Handle messages that contain neither body format.
Chilkat Lua Downloads
local chilkat = require("chilkat")
-- Assumes Chilkat is unlocked. See Global Unlock Sample.
local email = chilkat.Email.new()
local success = email:load_eml("with-attachments.eml")
if not success then
print(email.last_error_text)
return
end
print("From: " .. email.from)
print("Subject: " .. email.subject)
print("Date: " .. email.email_date_str)
local i = 0
while i < email.num_to do
print("To: " .. email:get_to_name(i) .. " " .. email:get_to_addr(i))
i = i + 1
end
local referenceId = email:get_header_field("X-Reference-ID")
if email.last_method_success then
print("Reference: " .. referenceId)
end
if email:has_plain_text_body() then
print(email:get_plain_text_body())
elseif email:has_html_body() then
local reader = chilkat.HtmlToText.new()
print(reader:to_text(email:get_html_body()))
else
print("No text or HTML body.")
end