We have moved at community.getvera.com

Author Topic: Vera UI4 How to get Email notification working using the Lua smpt socket  (Read 8902 times)

Offline PBO

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
Recently I bought  a Vera 2 system  with a  few power switches ( Everspring AN157 and AN158)  for evaluation first and  to be used later in my second home for control purposes.
I upgraded the unit to the latest beta release firmware 1.1.1234

I had in mind to build some extra functionality to control  the status of my switches after a power line failure on a single phase.
For instance If  the switch  becomes unpowered its state will be OFF after power comes up again while Vera’s event timer still could be programmed to be in the ON state. So I would like to send a Email notification by checking  the device Commfailure flag  and then using the Lua smpt socket for the notification.

There are a few more events I would  like to check this way other then the device status change notification used  in  the Scene tab “Notification”.  Since the Vera UI4  does not have other options yet for notification I was looking for a different way of notification and without using  de MIOS server facility.

I tried the event notification described in  the topic Device loses communication with MiCasaVerde found here: http://forum.micasaverde.com/index.php?topic=5330.0
I used exactly the same code but for some reason I cannot get it to work in the scene tab  Luup . Of course I did change the user variables to match the email account.

Running the code in Micasaverde developers test LUUP code (lua) does not give me a clue.
It runs successfully without code error. But only if I ad the code “return true” on the end otherwise I get “Code error”.
This seems to be necessary for  some reason, all other code I tested in test LUUP code  works fine this way.
(Can somebody explain why I need to put “return true”?).

There is another topic which describes a useful way how to do email notification based on the same  smtp socket in this topic:
Alerter for Drowsy Devices (ADD)
See: http://forum.micasaverde.com/index.php?topic=5130.0
In both topics it looks that these examples should work fine within the Vera V2 UI4 systems .

In another topic: UI4: creating users without a myMIOS account
See http://forum.micasaverde.com/index.php?topic=4323.0
Here however it seems impossible in the Vera UI4 to use the smpt socket option.

Am I right or  do I  mix up things now ?

Who can help me out ?.

Offline strangely

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3722
  • Karma: +34/-2
  • Vera 1,3 & V light
Are you sure you have your SMTP server settings correct, and that they don't require an SSL or TSL connection?
Kwickset locks, HA01C, HA14C, HA02C, HA03C, HA05C, HA04C, HA07C, HA09C, Aeon HEM, GE 45604, 45606, 45609, ZDP100, VRF01-1LZ, WDTC-20, HA18WD, WDHA-12R, HRDS1, HM-TS001, AC1-ZW, TV-IP110, BL-C210A, LUUP control- EtherRain8, DSC Alarm, HDMI matrix, HR24-200, Panasonic TV, SQblaster

Offline PBO

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
Thanks for the fast reply strangely.
I checked this but my smtp server does not require SSL or TSL. I used the same settings as in my outlook account.
I also  did portforwarding  port 25 in my modem just in case it was neccesary.
Will  Vera  report  the errors in the log if smtp server settings would be wrong ?

 I have added the most recent code here to check for any error.

Offline Ap15e

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1998
  • Karma: +12/-0
Try adding

Code: [Select]

to the code (just after the call to smtp.send).
« Last Edit: April 04, 2011, 07:37:05 am by Ap15e »

Offline PBO

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
Finally I got it to work !
Since my email account does not require Authentification  from my home IP  I removed
password = SMTP_AUTH_PW
from the send.smtp string and the variable USER_SENDING must contain my emailadress.
I did a telnet sesion first to the smtp server of my ISP to find this out.
This is the code that works for me now:
Code: [Select]
-- BEGIN user adjustable variables

  local SMTP_SERVER = "smtp.tiscali.nl"
  local SMTP_PORT = "25"
  local USER_SENDING = "my_email_adress"
  local USER_RECEIVING = "my_email_adress"

local smtp = require("socket.smtp")

local from = USER_SENDING
local rcpt = {USER_RECEIVING}

local subject_out = "test2"

local message_out = "hello"


  local mesgt = {
                  headers = {
                              to   = USER_RECEIVING,
                              from = from,
                              subject = subject_out
                  body    = message_out

  local r, e = smtp.send{ from     = from,
             rcpt     = rcpt,
             source   = smtp.message(mesgt),
             server   = SMTP_SERVER,
             port     = SMTP_PORT

I tried the same with  my Gmail address  by adding the code
user = SMTP_AUTH_USER and  password = SMTP_AUTH_PW  again and using my Gmail account details since Gmail requires a username and password.
 Unfortunately this seems not to work  because Gmail uses TSL and I read similar results in other micasaverde topics.
Anybody a solution for this ?

Offline stockvalues

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
Has anyone been able to get SMTP emails working where the server requires user name and password to authenticate rather than IP address?
I am trying this with U5. The server I am using, unlike GMail, does not use SSL/STARTTLS, but it does authenticate with user name and password and not by IP address.
Like everyone else, I require("socket.smtp") but I get no emails when I run my tests.

Also, has anyone tried the alternate Lua SMTP from nmap.org, instead of the very questionable implementation available through socket.smtp?