Sample code for 30+ languages & platforms
Rust

Get a Mail-Merge Replacement String by Pattern

See more Email Object Examples

Demonstrates the Chilkat Email.GetReplaceString2 method, which returns the replacement string for a previously-defined pattern/replacement pair, looked up by the pattern itself (a mail-merge feature). This example defines two pairs and looks up the replacement for one pattern by name.

Background: Where GetReplaceString fetches a replacement by its numeric position, GetReplaceString2 fetches it by the pattern — convenient when you already know the token (say FIRST_NAME) and just want its configured substitution without scanning the whole list.

Chilkat Rust Downloads

Rust
// Demonstrates the GetReplaceString2 method, which returns the replacement string for a
// previously-defined pattern/replacement pair, looked up by the pattern itself (a
// mail-merge feature).

let email = chilkat::Email::new();
email.set_subject("Hello FIRST_NAME");
email.set_body("Dear FIRST_NAME, welcome to CITY.");

let _ = email.set_replace_pattern("FIRST_NAME", "John");
let _ = email.set_replace_pattern("CITY", "Denver");

// Look up the replacement for a specific pattern.
let repl = email.get_replace_string2("FIRST_NAME").unwrap_or_default();
println!("FIRST_NAME -> {}", repl);