Just wanted to put up this small example for an email notification on a leak sensor status change. It will send out email when server detects a leak on sensor. I used information from another post in the forum and adapted it, sorry if it is not exactly the cleanest, but it works. Hope it helps someone. Make sure you change sensor info with your info.
public void Setup()
{
EmailHelper.SetupSmtp("This email address is being protected from spambots. You need JavaScript enabled to view it.", "password", "SMTP Server info", server "port", true);
EmailHelper.SendEmail("This email address is being protected from spambots. You need JavaScript enabled to view it.", "This email address is being protected from spambots. You need JavaScript enabled to view it.", "Subject", "Message");
}
public void Run()
{
EventHelper.ModuleChangedHandler((o, m, p) =>
{
Console.WriteLine(m.Address + " in program id "+ Program.ProgramId.ToString()+ " property "+ p.Property + " value " + p.Value);
if ((m.Domain == Domains.ESP8266) && (m.Address == "N2S6") && (p.Property == "Sensor.Leak") && (p.Value == "1"))
{
EmailHelper.SetupSmtp("This email address is being protected from spambots. You need JavaScript enabled to view it.", "password", "SMTP Server info", server "port", true);
EmailHelper.SendEmail("This email address is being protected from spambots. You need JavaScript enabled to view it.", "This email address is being protected from spambots. You need JavaScript enabled to view it.", "Subject", "Message");
}
return true;
});
Thank you for example program. Just one correction. EventHelper.ModuleChangedHandler shoud be used in Setup not Run. You do not need to setup crontab in this case. Modified program is like this
public void Setup()
{
EmailHelper.SetupSmtp("youaddress@somthing.com", "password", "SMTP Server info", server "port", true);
EventHelper.ModuleChangedHandler((o, m, p) =>
{
Console.WriteLine(m.Address + " in program id "+ Program.ProgramId.ToString()+ " property "+ p.Property + " value " + p.Value);
if ((m.Domain == Domains.ESP8266) && (m.Address == "N2S6") && (p.Property == "Sensor.Leak") && (p.Value == "1"))
{
EmailHelper.SendEmail("tyouaddress@somthing.com", "youaddress@somthing.com", "Subject", "Message");
}
return true;
});
}
public void Run()
{
}
cdj wrote: Hi guys, i'm just try to send email when a door is open with a mysensors node. I've changed in code :
public void Setup()
{
EmailHelper.SetupSmtp("mymail@gmail.com", "mygmailpass", "smtp.gmail.com", 587, true);
EventHelper.ModuleChangedHandler((o, m, p) =>
{
Console.WriteLine(m.Address + " in program id "+ Program.ProgramId.ToString()+ " property "+ p.Property + " value " + p.Value);
if ((m.Domain == Domains.MYSENSORS) && (m.Address == "N0S3") && (p.Property == "Sensor.DoorWindow") && (p.Value == "1"))
{
EmailHelper.SendEmail("mymail@gmail.com", "mymail@gmail.com", "Porta Ufficio Aperta", "Porta aperta !");
}
return true;
});
}
public void Run()
{
}
but no mail arrive... something wrong ? how to debug it ?
what to put in cron job ? five asterisk ?
Thanks
Dario
I'm using gmail account and google stops sending email two weeks ago. It looks like google filters those messages. Or maybe problem is with certificates and I need to update certificates - update procedure is in tutorials. I didn't have time to test it.
If I remember correctly one of forum members use yahoo account and it works without problems.
SendEmail function returns status if message is sent successful or not. It's all written in tutorials.