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

Create an email with plain-text and HTML bodies

See more Email Object Examples

Set the From and Reply-To addresses, add a recipient, and provide plain-text and HTML versions of the same body. Save the message as text-and-html.eml.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

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

local email = chilkat.Email.new()
email.from_name = "Sam Lee"
email.from_address = "sam@example.com"
email.reply_to = "replies@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 = "Sample message"
email.charset = "utf-8"
-- A custom header can carry a reference alongside the standard message fields.
email:add_header_field("X-Reference-ID", "REF-42")
success = email:add_plain_text_alternative_body("Read more at https://example.com/details.")
if not success then
    print(email.last_error_text)
    return
end

success = email:add_html_alternative_body("<p><a href='https://example.com/details'>Read more</a></p>")
if not success then
    print(email.last_error_text)
    return
end

success = email:save_eml("text-and-html.eml")
if not success then
    print(email.last_error_text)
    return
end

print("Saved text-and-html.eml.")