cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

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

No ratings

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);

        }

    }

Version history
Last update:
‎Jun 01, 2016 11:11 AM
Updated by:
Labels (2)