Sample code for 30+ languages & platforms
DataFlex

Count the Replace Patterns Set on an Email

See more Email Object Examples

Demonstrates the read-only Chilkat Email.NumReplacePatterns property, which returns how many replacement patterns have been set via SetReplacePattern. When replacement patterns are present, the email bodies and header fields are modified by applying the search/replacement strings during the sending process. Pattern indexes are zero-based. This example sets two patterns and prints the count.

Background: This is Chilkat's built-in mail merge. You compose one email containing placeholder tokens (for example FIRST_NAME or CITY), register each token and its replacement with SetReplacePattern, and the substitutions are applied when the message is sent — letting you personalize a bulk mailing without building a separate message for every recipient.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoEmail
    Boolean iSuccess
    Integer iTemp1

    //  Demonstrates the read-only Email.NumReplacePatterns property.  Replace patterns are
    //  search/replacement strings (set with SetReplacePattern) that are applied to the email
    //  bodies and header fields during mail-merge sending.  Indexes are zero-based.

    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End
    Set ComSubject Of hoEmail To "Hello FIRST_NAME"
    Set ComBody Of hoEmail To "Dear FIRST_NAME, your order ships to CITY."

    Get ComSetReplacePattern Of hoEmail "FIRST_NAME" "John" To iSuccess
    Get ComSetReplacePattern Of hoEmail "CITY" "Denver" To iSuccess

    Get ComNumReplacePatterns Of hoEmail To iTemp1
    Showln "NumReplacePatterns = " iTemp1


End_Procedure