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

Forward an email as an attachment

See more Email Object Examples

Attach the original Email to a new message as a message/rfc822 part. The recipient can open the attached email and read its original headers and body.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

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

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

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

email.subject = "Forwarded message"
email.body = "The original email is attached."
success = email:attach_email(original)
if not success then
    print(email.last_error_text)
    return
end

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

print("Saved forward-as-attachment.eml.")