In the SCADA applications, sometimes you need to send email notifications or SMS to your cell phones to know what your machines or processes are doing when you’re not in front of them.
Here is an example about sending email notifications and SMS using ATSCADA Alarm Tools by c# language.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using System.Windows.Forms;
using ATSCADA;
using System.Net.Mail;
using System.IO;
namespace EmailSMSProgramming
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btSendEmail_Click(object sender, EventArgs e)
{
ATSCADA.iWinTools.iEmail email = new ATSCADA.iWinTools.iEmail(); // Create email object
string toEmail = “example@gmail.com“;
email.Message.To.Add(toEmail); // Recipients email ID
email.Message.Subject = “Email Subject“; // Email Subject
email.Message.Body = “Text body“; // text body
//Attach files
if (File.Exists(@”C:\Program Files\ATPro\ATSCADA\Reports\DataGeneral” + “.xls”))
{
Attachment _data = new Attachment(@”C:\Program Files\ATPro\ATSCADA\Reports\DataGeneral” + “.xls”);
email.Message.Attachments.Add(_data);
}
//Send email
email.SendEmail(); // send email to recipients
email.Message.Dispose();
email.Dispose();
}
private void btSendSMS_Click(object sender, EventArgs e)
{
//SMS
ATSCADA.iWinTools.iSMS sms = new ATSCADA.iWinTools.iSMS(); // create SMS object
sms.COMPort = “COM11.115200.8.None.One”; // set port for SMS modem
sms.Message = “message content”; // message content
string recipient = “your phone number”; // recipient phone number
sms.Close();
sms.Open();
sms.sendMsg(recipient.Trim()); // send SMS to recipient
sms.DeleteMsg(); // clear SMS
sms.Close();
sms.Dispose();
}
}
}