17.10. Dynamically Changing Email Subjects and Recipients

The ASP processor in Gamma allows you to embed the result of any Gamma expression within the subject and recipient fields of an email. To do this on the subject field, you would use the same <%= %> syntax as is available for messages, for example:

The Sine value is now <%= $DataSim:Sine %>

would put the value of the DataSim:Sine point into the subject line of the email or message.

This syntax, explained in a the end of Section 17.4, “Defining the Email Message” can also be used to insert addresses for one or more the message recipients, by creating a point that contains the list of recipient names. The value of this point could then be changed externally based on who is on-call or is logged into an attached SCADA system. For example, a point in the default domain named CurrentOperatorEmail, would be entered in the Recipients: field like this:

<%= $default:CurrentOperatorEmail %>

If you need a more complex calculation to determine the recipients, you can create a Gamma script that loads when the DataHub instance starts. For example, to change the email based on the value of a point, you could do something like this:

function choose_mail_recipient()
{
    if ($DataSim:Sine > 0.5)
        "[email protected]";
    else
        "[email protected]";
}

and then put the appropriate function call into the email recipient list, like this:

<%= choose_mail_recipient() %>

Notice that the expression within <%= %> does not end with a semicolon. This syntax requires a Gamma expression, not a Gamma statement. Effectively, it needs to be code that would be syntactically correct in this statement:

x = insert_expression_here;

You can add as many function statements to your script as you like. Don't use method statements for this, since they are just for scope of the class of that script. Once a function has been defined in a running Gamma script, it is available to all other running Gamma programs. If you have created other Gamma programs, put this one at the top of the list, so that the function becomes available before those programs start. The Email/SMS program starts after the programs in the list.