Sample code for 30+ languages & platforms
Lua

MIME Multipart Boundary and Preamble Properties

See more MIME Examples

Demonstrates the Boundary property, which gets or sets the raw boundary token of a multipart entity (without surrounding quotation marks), and UseMmDescription, which controls whether the conventional preamble text is emitted when serializing a multipart entity.

Background. A multipart boundary separates the constituent parts. Chilkat quotes the token automatically in the header when required. The preamble is ignored by MIME-aware readers and is off by default.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local mime = chilkat.Mime.new()

-- Create a multipart/mixed entity.
local success = mime:new_multipart_mixed()
if not success then
    print(mime.last_error_text)
    return
end

-- Boundary is the raw boundary token, without surrounding quotation marks.  Chilkat quotes it
-- automatically in the serialized header when required.
mime.boundary = "example-boundary"

-- UseMmDescription controls whether the conventional preamble text
-- "This is a multi-part message in MIME format." is emitted.  The default is false.
mime.use_mm_description = true

-- Add a simple part so the multipart has content.
local part = chilkat.Mime.new()
success = part:set_body_from_plain_text("First part.")
if not success then
    print(part.last_error_text)
    return
end

success = mime:append_part(part)
if not success then
    print(mime.last_error_text)
    return
end

print("Boundary = " .. mime.boundary)

local mimeStr = mime:get_mime()
if not mime.last_method_success then
    print(mime.last_error_text)
    return
end

print(mimeStr)