General Email Notification

9 years 8 months ago #636 by tonyn79
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;
});

Console.WriteLine("test");
}
The following user(s) said Thank You: VasilijHCN

Please Log in or Create an account to join the conversation.

9 years 8 months ago #641 by EasyIoT
Replied by EasyIoT on topic General Email Notification
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()
{
}
The following user(s) said Thank You: VasilijHCN

Please Log in or Create an account to join the conversation.

9 years 8 months ago #647 by tonyn79
Replied by tonyn79 on topic General Email Notification
Cool, Thank you for the changes. Seems to make it a bit simpler. :cheer:

Please Log in or Create an account to join the conversation.

9 years 6 months ago #1266 by cdj
Replied by cdj on topic General Email Notification
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

Please Log in or Create an account to join the conversation.

9 years 6 months ago #1268 by EasyIoT
Replied by EasyIoT on topic General Email Notification

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.
The following user(s) said Thank You: cdj

Please Log in or Create an account to join the conversation.

9 years 6 months ago - 9 years 6 months ago #1269 by cdj
Replied by cdj on topic General Email Notification
Thanks, i've omitted certification part on server.
Tomorrow i try if it works... but 1st of all thanks for answer !

Dario

Please Log in or Create an account to join the conversation.

Time to create page: 0.267 seconds

Forum latest

  • No posts to display.