Sample code for 30+ languages & platforms
Lua

Serialize MIME to a StringBuilder

See more MIME Examples

Demonstrates the Chilkat Mime.GetMimeSb method, which serializes the complete MIME entity and appends it to a StringBuilder. The only argument is the StringBuilder; existing content is preserved.

Background: Serializing into a StringBuilder avoids creating a new string and is convenient when you are accumulating output or building a larger document. Because it appends, you can assemble several pieces in one buffer. As with GetMime, use the BinData form for content with arbitrary binary bytes.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- Demonstrates the Mime.GetMimeSb method, which serializes the complete MIME entity and appends
-- it to a StringBuilder.  The only argument is the StringBuilder.

local mime = chilkat.Mime.new()

local success = mime:set_body_from_plain_text("Hello, this is the message body.")
if not success then
    print(mime.last_error_text)
    return
end

-- Append the serialized MIME to a StringBuilder.  Existing content is preserved.
local sb = chilkat.StringBuilder.new()
success = mime:get_mime_sb(sb)
if not success then
    print(mime.last_error_text)
    return
end

print(sb:get_as_string())