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

Create, save, and reopen a plain-text email

See more Email Object Examples

Set the sender, recipient, subject, and plain-text body. Save the result as an EML file, then open it in a second Email object and read its contents.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

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

local email = chilkat.Email.new()
email.from = "Sam Lee <sam@example.com>"
local success = email:add_to("Alex Rivera", "alex@example.net")
if not success then
    print(email.last_error_text)
    return
end

email.subject = "Hello"
email.body = "This is a plain-text message."
success = email:save_eml("message.eml")
if not success then
    print(email.last_error_text)
    return
end

local received = chilkat.Email.new()
success = received:load_eml("message.eml")
if not success then
    print(received.last_error_text)
    return
end

print(received.from)
print(received.subject)
print(received:get_plain_text_body())