Lua
Lua
Change the Filename of an Attachment
See more Email Object Examples
Demonstrates the Chilkat Email.SetAttachmentFilename method, which changes the filename of the attachment at a given zero-based index. This example adds an attachment and renames it, printing the filename before and after.
Background: The attachment filename is what a recipient sees and what most clients suggest when saving the file. Renaming it is handy when the original name is unclear, unsafe, or generic — for example giving a machine-generated
tmp12345 a meaningful name like invoice.pdf before sending.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- Demonstrates the SetAttachmentFilename method, which changes the filename of the
-- attachment at the given zero-based index.
local email = chilkat.Email.new()
email.subject = "Set attachment filename"
email:add_string_attachment("oldname.txt", "Some notes.")
print("Filename before: " .. email:get_attachment_filename(0))
-- Change the filename of the first attachment (index 0).
local success = email:set_attachment_filename(0, "newname.txt")
if not success then
print(email.last_error_text)
return
end
print("Filename after: " .. email:get_attachment_filename(0))