0
Answered

Email/SMTP traps

Allan Kowsky 6 years ago updated by Vladimir Ovchinnikov (expert) 6 years ago 5

Hello, I have an Hikvision NVR and would like to get the motion detect from the Ip cameras to trigger light, ect. It is possible to send an Email or send Events via SMTP from the NVR. So the question is, is it possible to receive Emails/SMTP traps in iridiummobile UMC Server? 

GOOD, I'M SATISFIED

perfect, thanks

Satisfaction mark by Allan Kowsky 6 years ago
Answered

Hello.

Example of sending from iridium via external SMTP.


var smtp_driver = IR.CreateDevice(IR.DEVICE_CUSTOM_TCP, "SMTP", {
   Host: "smtp.gmail.com",
   Port: 465,
   SSL: true,
   SendMode: IR.ALWAYS_CONNECTED,
   ScriptMode: IR.SCRIPT_ONLY
});
             
function send_email (name_from, email_from, password, email_to, header, message)
{
   IR.AddListener(IR.EVENT_RECEIVE_TEXT, smtp_driver, sender);
   send("hello");
   send("auth");
      
   function send(command)
   {
      switch (command)
      {
         case "hello":
            smtp_driver.Send(["EHLO smtp.gmail.com\r\n"]);
            break;         
         case "auth":    
            smtp_driver.Send(["AUTH LOGIN\r\n"]);
            break;  
         case "login":  
            smtp_driver.Send([IR.Base64Encode(email_from) + "\r\n"]);
            break;  
         case "password":    
            smtp_driver.Send([IR.Base64Encode(password) + "\r\n"]);
            break;  
         case "from":    
            smtp_driver.Send(["MAIL FROM:<"+email_from+">\r\n"]);
            break;
         case "to":    
            smtp_driver.Send(["RCPT TO:<"+email_to+">\r\n"]);
            break;  
         case "data":   
            smtp_driver.Send(["DATA\r\n"]);
            break;  
         case "string":
            smtp_driver.Send(["From: "+name_from+" <"+email_from+">\r\nTo:<"+email_to+">\r\nSubject: "+header+"\r\nContent-Type: text/plain\r\n\r\n"+message+"\r\n.\r\n"]);
            break;  
         case "quit":       
            smtp_driver.Send(["QUIT\r\n"]);
            break;                   
      }
   }

   function sender(text)
   {                
      if(text.indexOf("334 VXN", 0) + 1)
      {
         send("login");
         send("password");
      }
      if(text.indexOf("Accepted", 0) + 1)
      {
         send("from");
           send("to");
           send("data");                                 
           send("string");
         IR.SetTimeout(200, function () {
             send("quit"); IR.RemoveListener(IR.EVENT_RECEIVE_TEXT, smtp_driver, sender);
         IR.Log("message sent");
         });    
      }
   }
}

okay, thanks, it Can send emails, How about the receive part? I want to send from my NVR to the UMC server. Regards..

What do you want to send to UMC? Video file?

This is what I want to receive. Every time there is movement in the IP cam this mail will be sent to the UMC Server.

Motion Detected in Stue(D1) should trigger an variable in the UMC. 


This is an automatically generated e-mail from your NVR.

EVENT TYPE:    Motion Detected
EVENT TIME:    2018-07-17,10:56:03
NVR NAME:      Network Video Recorder
NVR S/N:       1620171120CCRR136867949WCVU
CAMERA NAME(NUM):   Stue(D1)

Example of creating a driver to connect to Gmail IMAP mail:


var smtp_driver = IR.CreateDevice(IR.DEVICE_CUSTOM_TCP, "SMTP", {
   Host: "imap.gmail.com",
   Port: 993,
   SSL: true,
   SendMode: IR.ALWAYS_CONNECTED,
   ScriptMode: IR.SCRIPT_ONLY,

   Login: "your_full_email_address",

   Password: "Gmail_Password"

});

You need a IMAP client to receive emails and sort them by subject. You can implement it in pure JavaScript, but we do not have ready-made examples. Perhaps, you will borrow the decision from here.