SendMail

You can use the SendMail function to send an email notification from the system to one or more recipients, optionally with attachments, using either the default or tenant-specific email configuration.

When to use

You can use this function to:

  • Send emails with file attachments to users.
  • Implement automated report distribution.
  • Send notifications during approval workflows that require document review.
  • Send generated reports or exports to users.

When not to use

You cannot use this function for simple notifications without attachments. Use Notify instead.

Syntax

Syntax 1
Send Email Without Attachments.
long SendMail(string EMailTemplate, int addresseeType, string addressee, bool useTenantCustomMailConfiguration, params string[] args)
Parameters
Parameter Type Required Description
EMailTemplate string Yes The code of the Email Template form to be used. Defines the message format and content.
Note: The code must match an existing template in the system.
addresseeType int Yes Numeric code specifying recipient type. Possible values:
  • 0 = User (individual user)
  • 1 = Role (all users with specified role)
  • 2 = Group (all users in specified group)
addressee string Yes The recipients of the email. Can be a specific user code, group name, or role name.
Note:  Multiple recipients separated by semicolon (;).
useTenantCustomMailConfiguration bool Yes Configuration flag for tenant-specific email settings. Possible values:
  • true = Use tenant-specific/custom email settings.
  • false = Use global or default email configuration.
args string[] Optional The variable-length parameter array for dynamic template content.
Note: The parameters are referenced in templates as [%1], [%2], etc.
Example
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; 
        } 
    } 
}
Arguments
  • EMailTemplate - MONTHLY_SALES_REPORT
  • addresseeType - 0
  • addressee - FSI
  • useTenantCustomMailConfiguration – false
Syntax 2
long SendMail(string EMailTemplate, int addresseeType, string[] addressee, List<EmailFileAttachment> attachments, bool useTenantCustomMailConfiguration, string[] args)
Parameters
Parameter Type Required Description
EMailTemplate string Yes The code of the Email Template form to be used. Defines the message format and content.
Note: The code must match an existing template in the system.
addresseeType int Yes Numeric code specifying recipient type. Possible values:
  • 0 = User (individual user)
  • 1 = Role (all users with specified role)
  • 2 = Group (all users in specified group)
addressee string Yes The recipients of the email. Can be a specific user code, group name, or role name.
Note:  Multiple recipients separated by semicolon (;).
useTenantCustomMailConfiguration bool Yes Configuration flag for tenant-specific email settings. Possible values:
  • true = Use tenant-specific/custom email settings.
  • false = Use global or default email configuration.
args string[] Optional The variable-length parameter array for dynamic template content.
Note: The parameters are referenced in templates as [%1], [%2], etc.
attachments List Yes The list of file attachments to include.
Note: Each entry contains file name with full path. This parameter is available only in Syntax 2.
Example
using System; 
using System.IO; 
using System.Collections.Generic; 
using Formation.Shared.Defs; 
  
class ActionScript : FcProcFuncSetEventWF 
{ 
    public long wf_start() 
    { 
        try 
        { 
            // List of full file paths to attach 
            List<string> fileNames = new List<string> { "Example1.pdf", "Example2.pdf", "Image1.png", "Image2.jpg", "SummaryDocument1.docx" }; 
  
            // Build attachment list from file names 
            List<EmailFileAttachment> attachments = new List<EmailFileAttachment>(); 
            foreach (string fileName in fileNames) 
            { 
                byte[] fileBytes = File.ReadAllBytes(fileName); 
                attachments.Add(new EmailFileAttachment(fileBytes, fileName)); 
            } 
  
            // Send the email with attachments 
            long rtnval = SendMail("MONTHLY_SALES_REPORT", 0, new string[] { "FSI" }, attachments, false, new string[] { "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; 
        } 
    } 
}
Arguments
  • EMailTemplate - NEW_TEMPLATE2
  • addresseeType - 0
  • addressee - FSI, ADMIN
  • useTenantCustomMailConfiguration - false

This example sends an email to specified recipients(FSI, ADMIN) and attachments using a given template NEW_TEMPLATE2, without applying tenant-specific email settings.

Syntax 3
Send Email With Direct Message Content and String Array Attachments.
long SendMail(ref string[] addressees, string subject, string message, ref string[] attachments, bool isHtml = true, bool useTenantCustomMailConfiguration = false)
Parameters
Parameter Type Required Description
subject string Yes The email subject line.
message string Yes The body of the email.
Note: This can be plain text or HTML depending on isHtml (support of the mail system).
addressees string [Passed by Reference] Yes An array of recipients for the notification.

The array can contain one or more users, groups, or roles.

The array is passed by reference so the system can validate recipients, remove invalid or duplicate entries, and update the existing array.

After execution, addressees can contain actual email addresses.

attachments string[] Passed by Reference

An array of strings representing file names (including full paths) that will be attached to the email.

Note: The attachments array is passed by reference so that the values in the array can be updated in the cache.
isHtml bool Optional

Enables users to embed HTML elements in the mail message.

Depending on the support of the mail system they use, this can add additional functionality such as hyperlinks to the mail message.

By default, the parameter is set to True, which sets the html support on the outgoing email message.

useTenantCustomMailConfiguration bool Optional Configuration flag for tenant-specific email settings: Possible values:
  • true- Use tenant specific or custom email settings.
  • false- Use global or default email configuration.
Examples
using System; 
using System.Collections.Generic; 
using Formation.Shared.Defs; 
  
class ActionScript : FcProcFuncSetEventWF 
{ 
    public long wf_start() 
    { 
        try 
        { 
            // Define recipients 
            string[] addressees = new string[] { "FSI" }; 
  
            // Define attachments as file paths 
            string[] attachments = new string[] { "Example1.pdf", "Example2.pdf", "Image1.png", "Image2.jpg", "SummaryDocument1.docx" }; 
  
            // Send the email 
            long rtnval = SendMail(ref addressees, "Monthly Sales Report", "Please find the attached sales report for April 2026.", ref attachments, true, false); 
            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; 
        } 
    } 
}
Syntax 4
Send Email With Direct Message Content and List of Email Attachments.
SendMail(ref string[] addressees, string subject, string message, ref List<EmailFileAttachment> attachments, bool isHtml = true, bool useTenantCustomMailConfiguration = false)
Parameters
Parameter Type Required Description
subject string Yes The email subject line.
message string Yes The body of the email.
Note: This can be plain text or HTML depending on isHtml (support of the mail system).
addressees string[] [Passed by Reference] Yes An array of recipients for the notification.

The array can contain one or more people or entities who will receive the email when the SendMail function is executed.

The array is passed by reference so the system can validate recipients, remove invalid or duplicate entries, and update the existing array.

After execution, addressees can contain actual email addresses.

attachments string[] Passed by Reference

An array of strings representing file names (including full paths) that will be attached to the email.

Note: The attachments array is passed by reference so that the values in the array can be updated in the cache.
isHtml bool Optional

Enables users to embed HTML elements in the mail message.

Depending on the support of the mail system they use, this can add additional functionality such as hyperlinks to the mail message.

By default, the parameter is set to True, which sets the html support on the outgoing email message.

useTenantCustomMailConfiguration bool Optional Configuration flag for tenant-specific email settings: Possible values:
  • true- Use tenant specific or custom email settings.
  • false- Use global or default email configuration.
Example
using System; 
using System.IO; 
using System.Collections.Generic; 
using Formation.Shared.Defs; 
  
class ActionScript : FcProcFuncSetEventWF 
{ 
    public long wf_start() 
    { 
        try 
        { 
            // Define recipients 
            string[] addressees = new string[] {"FSI"}; 
  
            // Build attachment list from file names 
            List<EmailFileAttachment> attachments = new List<EmailFileAttachment>(); 
            List<string> fileNames = new List<string> { "Example1.pdf", "Example2.pdf", "Image1.png", "Image2.jpg", "SummaryDocument1.docx" }; 
            foreach (string fileName in fileNames) 
            { 
                byte[] fileBytes = File.ReadAllBytes(fileName); 
                attachments.Add(new EmailFileAttachment(fileBytes, fileName)); 
            } 
  
            // Send the email 
            long rtnval = SendMail(ref addressees, "Monthly Sales Report", "Please find the attached sales report for April 2026.", ref attachments, true, false); 
            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; 
        } 
    } 
}

Return Value

The application returns a value one (1) when the email is sent successfully.

Prerequisites

  • The users must have valid email addresses configured.
  • The attachment files must exist and be accessible.