Skip to main content
5-Regular Member
June 1, 2016

Axeda Groovy Script: Send Email from Expression Rule triggered by Alarm

  • June 1, 2016
  • 0 replies
  • 1570 views

Sends an email with an alarm name passed in by an Expression Rule.

Parameters (passed in as arguments to ExecuteCustomObject in the Expression Rule):

  1. fromaddress
  2. toaddress

import com.axeda.drm.sdk.contact.Email

/*

* ExprRuleAlarmToEmail.groovy

*

* Sends an email with an alarm name passed in by an Expression Rule.

*

* @param fromaddress - (REQ):Str email address of sender.

* @param toaddress - (REQ): Str email address of recipient

*

*

* @note Should be executed from an Expression Rule like the following:

*

* Type: Alarm

* If: Alarm.severity > 490 && Alarm.severity < 700

* Then: ExecuteCustomObject("ExprRuleAlarmToEmail", "fake_sender@axeda.com","fake_recipient@axeda.com")

*

* @author Sara Streeter <sstreeter@axeda.com>

*/

try {

  String fromaddress = parameters.fromaddress

  String toaddress = parameters.toaddress

  String subject = "Axeda Alarm - ${alarm.name}"

  String body = "You are receiving this alarm ${alarm.name} because you are subscribed to its updates."

  sendEmail(fromaddress, toaddress, subject, body)

}

catch (Exception e) {

logger.error(e.message)

}

    public void sendEmail(String fromAddress,String toAddress,String subject, String body) {

        try {

            Email.send(fromAddress, toAddress, subject, body);

        } catch (AddressException ae) {

            logger.error(ae);

        }

    }