Sample code for 30+ languages & platforms
Lua

Add File Attachments to an Email

Demonstrates how to add one or more file attachments to an email.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local email = chilkat.Email.new()

email.subject = "This is a test"
email.body = "This is a test"
email.from = "support@chilkatsoft.com"
local success = email:add_to("Chilkat Admin", "admin@chilkatsoft.com")

-- To add file attachments to an email, call AddFileAttachment
-- once for each file to be attached.  The method returns
-- the content-type of the attachment if successful, otherwise
-- returns cknull

local contentType = email:add_file_attachment("something.pdf")
if not email.last_method_success then
    print(email.last_error_text)
    return
end

contentType = email:add_file_attachment("something.xml")
if not email.last_method_success then
    print(email.last_error_text)
    return
end

contentType = email:add_file_attachment("something.zip")
if not email.last_method_success then
    print(email.last_error_text)
    return
end

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

print("Saved EML!")