Sample code for 30+ languages & platforms
Lua

Get a Mail-Merge Replace Pattern

See more Email Object Examples

Demonstrates the Chilkat Email.GetReplacePattern method, which returns a replacement pattern — the search string — previously defined for mail-merge operations with SetReplacePattern. The index is zero-based. This example defines two patterns and enumerates them.

Background: In Chilkat's mail-merge, each entry is a pattern (a placeholder token such as FIRST_NAME) paired with a replacement string. GetReplacePattern retrieves the search side of the pair at a given index; GetReplaceString retrieves the matching replacement. Reading them back is useful for inspecting or logging exactly which substitutions will be applied when the message is sent.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- Demonstrates the GetReplacePattern method, which returns a replacement pattern (the
-- search string) previously defined for mail-merge operations with SetReplacePattern.
-- The index is zero-based.

local email = chilkat.Email.new()
email.subject = "Hello FIRST_NAME"
email.body = "Dear FIRST_NAME, welcome to CITY."

email:set_replace_pattern("FIRST_NAME", "John")
email:set_replace_pattern("CITY", "Denver")

local n = email.num_replace_patterns
for i = 0, n - 1 do
    print("Pattern " .. i .. ": " .. email:get_replace_pattern(i))
end