Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Download the Solution Example here: AlarmEmailAndSMS.dbsln

Name: AlarmEmailAndSMS

Software Version: 10.1


Summary

This sample demonstrates configuring to send an email and an SMS containing alarm information using the feature NotificationMethod every time an alarm event occurs.

Image Added


Technical Information

The NotificationMethod used in this solution example allows configuring your solution to send an email, an SMS, a message box, or speech the alarm message every time a conditional event alarm occurs. 

When the solution runs, the NotificationMethod is called every time a conditional event alarm occurs. Then, this method receives an Array of AlarmEventInfo as a parameter. See an example code below:

Code Block
languagec#
public void AlarmEvents(AlarmEventInfo[] events)

{

    //Protection in case events its null

    if (events == null)

        return;


    //Get the first event

    AlarmEventInfo event = events[0];

    if (event.State != 1)

        return;


    //Get information about the alarm event to create the body of the email

    string body = "Time: " + event.ActiveLocalTime.ToString() + "\n" +

    "Message = " +  event.Message + "\n" +

    "Area = " + event.Area + "\n" +

    "Group = " + event.Group + "\n" +

    "Tag = " +  event.TagName + "\n";


    //Code to send email           

    try

    {

        //Configuring the SMTP Client

        System.Net.Mail.SmtpClient mySmtpClient = new System.Net.Mail.SmtpClient(@Tag.smtpServer, 587);

        mySmtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;

        mySmtpClient.EnableSsl = true;

        mySmtpClient.UseDefaultCredentials = false;

        mySmtpClient.Credentials = new System.Net.NetworkCredential(@Tag.fromEmail, @Tag.passFromEmail);


        //Sending the email

        mySmtpClient.Send(@Tag.fromEmail, @Tag.toEmail, "Dmail notification", body);


    }

    catch (Exception ex)

    {

        @Info.Trace("Error sending message: " + ex.Message);

    }


}


Once in the NotificationMethod, you can send an email, send a message, send a message box, speech an alarm message, etc.


Reference Information

If sending emails is required in your solution, you can install a PlugIn with that functionality.

→ See Alarms for more information.


In this section:

Page Tree
root@parent
spacesV10