EmailTemplate
You can use the EmailTemplate function to generate a formatted email message from a predefined email template and dynamic parameters. The function supports template token replacement and provides template data for use with the SendMail method.
This function bridges the gap between email templates and file attachments by:
- Processing email templates with token replacements, similar to the Notify method.
- Returning template data for use with the
SendMailmethod. - Enabling email templates and file attachments to be used together.
When to use
You can use this function:
- When sending standardized notification emails in HTML or plain-text with dynamic content.
- During workflow automation requiring email notifications.
- When using email templates with the Notify method, where file attachments are not supported.
- When using file attachments with the
SendMailmethod.Note: You cannot use email templates. - When combining email templates and file attachments through the
EmailTemplateTextmethod.
Syntax
EmailTemplateText EmailTemplate(string template, params object[] args); EMailData EmailTemplate(string template, string[] UserLanguages, params string[] args);
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| template | string | Yes | The code or name of the email template created and managed by system administrators via the Email Template form.
Note: The template parameter supports both plain text and HTML formats.
|
| args | object[] (ParamArray) | Optional | The dynamic parameters passed to the template to replace placeholders. Each parameter corresponds to a placeholder identified by [%n] where n is the parameter index (1-based).
Note: The values are substituted in order.
|
Return Value
The application returns a new EmailTemplateText object if the operation is successful.
Prerequisites
- Email templates need to be created and configured by administrators.
- The template code needs to exist in the Email Template form.
- The number of parameters provided needs to match the template requirements.
Examples
- Example 1
-
// Template code: "Formula [%1] is ready for review by [%2]." EmailTemplateText msg; msg = EmailTemplate("NOTIFY_FORMULA_READY", "F12345", "QA Team"); // Result: "Formula F12345 is ready for review by QA Team."
- Description
-
This example generates a notification message by replacing [%1] with "F12345" and [%2] with "QA Team".
- Example 2
-
using System; using System.Collections.Generic; using Formation.Shared.Defs; class ActionScript : FcProcFuncSetEventWF { public long wf_start() { try { long rtnval = SendMail("MONTHLY_SALES_REPORT", 0, new string[] {"FSI"}, false, "April 2026", "Sales Department", "1,25,000"); if (rtnval == 1) { MessageList("Report email sent successfully"); } else { MessageList("Failed to send report email"); } return 111; } catch (Exception) { MessageList("Failed to send report email"); return -1; } } } - Description
-
This example demonstrates how a C# workflow script sends a templated email using the
SendMailfunction. The script applies dynamic parameters to the MONTHLY_SALES_REPORT email template and sends the message to the specified recipient.