Sample code for 30+ languages & platforms
Lua

Set a MIME Body from Plain Text

See more MIME Examples

Demonstrates the Chilkat Mime.SetBodyFromPlainText method, which sets the body as plain text. The only argument is the text. For ASCII input Chilkat uses text/plain with 7bit encoding; for non-ASCII it selects an appropriate charset and encoding.

Background: This is the simplest way to give a MIME entity a text body — Chilkat picks a sensible Content-Type and transfer encoding for you based on the content. Plain ASCII stays as 7bit with no charset, while text containing accented or non-Latin characters gets a charset (typically UTF-8) and a suitable encoding so it survives transmission intact. It is the text counterpart to SetBodyFromHtml and SetBodyFromXml.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- Demonstrates the Mime.SetBodyFromPlainText method, which sets the body as plain text.  The only
-- argument is the text.  For ASCII, Chilkat sets Content-Type: text/plain and a 7bit transfer
-- encoding; for non-ASCII it selects an appropriate charset and encoding.

local mime = chilkat.Mime.new()

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

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

print(mimeText)