We have moved at community.getvera.com

Author Topic: [_CODE_] SND - SMTP Notification Device (UPnP to SMTP bridge) V0.3a  (Read 21681 times)

Offline Ap15e

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1998
  • Karma: +12/-0
EOL, unsupported.

Installation:

Usage:
  • luup.call_action( "urn:upnp-ap15e-com:serviceId:SND1", "SendMail", { subject = 'Message from Vera', body = 'How are you today?' }, 11 )
    replace 11 with the SND device ID.

History:
V0.2   fix for DeviceType (thanks to oTi@), UPnP parameters: subject, body
V0.3   update for UI5
V0.3a removed isSingle from static json file for compatibility with UI4

Remarks:
  • RFC 2821 requires all lines of the message body to end with CRLF.

Download:
https://docs.google.com/open?id=0Bz4omZm4gYcsNWM0MDc5MDQtMzI3OC00YjA3LThkMTUtYTlmNWVlMWY2YTg4
« Last Edit: May 08, 2012, 12:57:22 pm by Ap15e »

Offline Henk

  • Hero Member
  • *****
  • Posts: 820
  • Karma: +3/-0
Re: [_CODE_] SND - SMTP Notification Device
« Reply #1 on: May 27, 2011, 05:17:56 pm »
Ok, so a generic device to call upon for notifications instead of having to implement the code for every device one needs notifications from...

That should cut down in duplicate code and Lua load....

Thanks @Ap15e

Ill set it up and let you know how it works!

--- edit---
first remark, downloading now works without having to sign in! Thats 1 improvement!!!

---edit 2--
Where would the luup line mentioned under usage go? In the luup code tab/field of a created event?
That is how i created it and it doenst send messages on the trigger set

--edit 3--
In the original code i had to comment out the AUTH lines since my SMTP server doesnt require them.
Now i have two emtpy fields in SND and am of course unable to comment then out of the code.
I remember that email didnt work with the lines of code active without input....
Can this be the reason why no messages sent so far?
« Last Edit: May 27, 2011, 05:36:22 pm by Henk »
| Vera2 @ UI4 1.1.1350 / 3.20 | Vera Lite @ UI5 | Vera 3 @ UI5 | 2x Merten  504519 | 1x Duewi  064374 | 1x Everspring SM103 doorbell mod |1 Y-cam IP cam | various LUUP plugins |

Offline JOD

  • Hero Member
  • *****
  • Posts: 1973
  • Karma: +4/-0
Re: [_CODE_] SND - SMTP Notification Device (UPnP to SMTP bridge)
« Reply #2 on: May 27, 2011, 11:13:52 pm »
@Henk, did you change the device number of the code to match the SND device that was created?
(luup.call_action( "urn:upnp-ap15e-com:serviceId:SND1", "SendMail", { message = 'Message from Vera' }, 11 )

*(replace 11 with the SND device ID.)

@Ap15e, works great.
"Message from Vera" appears in the emails subject (which is easily changed for the event)
Each of the 12 test emails generated had a single random letter or number in the body of the email when they were received.
w,u,5,a,d,c,u,m,o,f,0,5

JOD.
I'm sorry, my responses are limited. You must ask the right questions.

Offline oTi@

  • Community Beta
  • Master Member
  • ******
  • Posts: 4041
  • Karma: +32/-6
  • UI what ?!
Re: [_CODE_] SND - SMTP Notification Device (UPnP to SMTP bridge)
« Reply #3 on: May 28, 2011, 01:13:14 am »
Yup, works!

Didn't get any random characters; body claimed empty by email reader.

F/R: customizable body (or perhaps switch to select whether message goes into subject or body).
Dezwaved at the moment...

Offline Henk

  • Hero Member
  • *****
  • Posts: 820
  • Karma: +3/-0
Re: [_CODE_] SND - SMTP Notification Device (UPnP to SMTP bridge)
« Reply #4 on: May 28, 2011, 04:14:24 am »
@Henk, did you change the device number of the code to match the SND device that was created?
(luup.call_action( "urn:upnp-ap15e-com:serviceId:SND1", "SendMail", { message = 'Message from Vera' }, 11 )

*(replace 11 with the SND device ID.)

JOD.

@JOD yes i did, i used the device ID of the light that i was switching (15) and yes i know that was not the idea
and yes i used the ID of SND (24). No messages on both settingchanges
| Vera2 @ UI4 1.1.1350 / 3.20 | Vera Lite @ UI5 | Vera 3 @ UI5 | 2x Merten  504519 | 1x Duewi  064374 | 1x Everspring SM103 doorbell mod |1 Y-cam IP cam | various LUUP plugins |

Offline Henk

  • Hero Member
  • *****
  • Posts: 820
  • Karma: +3/-0
Re: [_CODE_] SND - SMTP Notification Device (UPnP to SMTP bridge)
« Reply #5 on: May 28, 2011, 04:16:20 am »
Got it to work!
Seemingly there are some spaces in the code when cutting and pasting it.
After removing the space after the SND device Id my messages started coming.

--edit--
Messages sent YES, messages received 0
Do i need to set the variables within quotes? (like "send.this@email.eu") and SMTPport "25"???

Strange thing is, ADD sends hearbeats perfectly with exactly the same settings as i used in SND

Q. Can the number of sent messages be purged?
A. Yes, by manually changing it back to 0 in the advanced tab

Q. Can ADD use this device too so that only one UpNP-SMTP bridge/code is needed in the system?

« Last Edit: May 28, 2011, 04:31:26 am by Henk »
| Vera2 @ UI4 1.1.1350 / 3.20 | Vera Lite @ UI5 | Vera 3 @ UI5 | 2x Merten  504519 | 1x Duewi  064374 | 1x Everspring SM103 doorbell mod |1 Y-cam IP cam | various LUUP plugins |

Offline Ap15e

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1998
  • Karma: +12/-0
Re: [_CODE_] SND - SMTP Notification Device (UPnP to SMTP bridge) V0.2
« Reply #6 on: May 28, 2011, 06:26:37 am »
SND V0.2 is available. Syntax has changed, see topmost post.

Offline oTi@

  • Community Beta
  • Master Member
  • ******
  • Posts: 4041
  • Karma: +32/-6
  • UI what ?!
Re: [_CODE_] SND - SMTP Notification Device (UPnP to SMTP bridge) V0.2
« Reply #7 on: May 28, 2011, 07:08:28 am »
SND V0.2 is available. Syntax has changed, see topmost post.
Nice; thanks! Works.

F/R: Prowl integration, or the PND cousin of this. :)
(I guess @axill's earlier work may be a reference.)
« Last Edit: May 28, 2011, 08:40:01 am by oTi@ »
Dezwaved at the moment...

Offline Henk

  • Hero Member
  • *****
  • Posts: 820
  • Karma: +3/-0
Re: [_CODE_] SND - SMTP Notification Device (UPnP to SMTP bridge) V0.2
« Reply #8 on: May 28, 2011, 11:51:03 am »
@Ap15e & @oTi@

I must look silly.... but i cant receive the email (ADD works...). I can only deduce that it isnt being sent by SND.
I SEE the SND device working (message counter stacks) so i know the luupcode in the event is working (with correct SND device ID)

I've tried everything from retyping all variables, stated the IP instead of name of my SMTP host
Set username/password to 0, tried "" in those fields... nothing!

I know for a fact this was the same issue i had with my ADD device, not mailing heartbeats.
I solved this by completly commenting out the AUTH_USER & SMTP_AUTH lines like shown below.

Code: [Select]
 local SMTP_SERVER = "my.smtp.host"
-- local SMTP_AUTH_USER = ""
-- local SMTP_AUTH_PW = ""        
  local SMTP_PORT = "25"
  local USER_SENDING = "sender@my.vera"
  local USER_RECEIVING = "receiver@gmail.com"

Only after actually commenting out the code, did my ADD device start to send heartbeats.
The only thing i can imagine now is that these fields are in the SND code and my SMTP host doesnt accept the empty request. Can i try and remove them from the apropriate xml to troubleshoot?
I know ill loose the variables then, but thats less bothersome than not receiving the notifications.

« Last Edit: May 29, 2011, 03:14:37 pm by Henk »
| Vera2 @ UI4 1.1.1350 / 3.20 | Vera Lite @ UI5 | Vera 3 @ UI5 | 2x Merten  504519 | 1x Duewi  064374 | 1x Everspring SM103 doorbell mod |1 Y-cam IP cam | various LUUP plugins |

Offline Henk

  • Hero Member
  • *****
  • Posts: 820
  • Karma: +3/-0
Re: [_CODE_] SND - SMTP Notification Device (UPnP to SMTP bridge) V0.2
« Reply #9 on: May 28, 2011, 12:12:12 pm »
YESSS!!!!

I edited the I_SND.xml and commented out these sections:

Code: [Select]
--- local SMTP_auth_user    
--- local SMTP_auth_password

---  SMTP_auth_user     = get_variable( SND_SERVICE, 'SMTPAuthUser'    , SND_DEVICE, ''   )
---  SMTP_auth_password = get_variable( SND_SERVICE, 'SMTPAuthPassword', SND_DEVICE, ''   )

---                               user     = SMTP_auth_user,
---                               password = SMTP_auth_password

And Bingo!!!! my mail notifications work.

Because i didnt need it after that i also edited the S_SND.xml and commented out this:
Code: [Select]
--  <stateVariable>
--    <name>SMTPAuthUser</name>
--    <sendEventsAttribute>no</sendEventsAttribute>
--    <dataType>string</dataType>
--    <defaultValue></defaultValue>
--    <shortCode>smtpauthuser</shortCode>
--  </stateVariable>

Whats left now is how to edit the json file... can i safely comment out stuff there?

@Ap15e
Is there another way to code this? or does it have to be hardcoded and users have to exclude the lines manually edit their xml files if they have the same issue i was having? Maybe you could code the variables in such a way that they only create output if there is actually data in the fields and not send the requests to the server emtpy?
« Last Edit: May 28, 2011, 01:03:14 pm by Henk »
| Vera2 @ UI4 1.1.1350 / 3.20 | Vera Lite @ UI5 | Vera 3 @ UI5 | 2x Merten  504519 | 1x Duewi  064374 | 1x Everspring SM103 doorbell mod |1 Y-cam IP cam | various LUUP plugins |

Offline Henk

  • Hero Member
  • *****
  • Posts: 820
  • Karma: +3/-0
Re: [_CODE_] SND - SMTP Notification Device (UPnP to SMTP bridge) V0.2
« Reply #10 on: May 28, 2011, 12:36:20 pm »
Functionalitywise, is it possible to add variables to the textbody like timestamp, day of week etc?
If so, are there standard luup variables to use then? I took a look at the wiki and found something like "os time()"
/but how would i incorporate that into the body of the message?
| Vera2 @ UI4 1.1.1350 / 3.20 | Vera Lite @ UI5 | Vera 3 @ UI5 | 2x Merten  504519 | 1x Duewi  064374 | 1x Everspring SM103 doorbell mod |1 Y-cam IP cam | various LUUP plugins |

Offline oTi@

  • Community Beta
  • Master Member
  • ******
  • Posts: 4041
  • Karma: +32/-6
  • UI what ?!
Re: [_CODE_] SND - SMTP Notification Device (UPnP to SMTP bridge) V0.2
« Reply #11 on: May 28, 2011, 01:46:57 pm »
YESSS!!!!
Excellent. For clarification, I use authentication on both my own server as well as my ISP's, so my situation is different. I do think this can be coded differently, although one could perhaps argue that the root problem is the robustness of the SMTP library.
« Last Edit: May 28, 2011, 01:54:54 pm by oTi@ »
Dezwaved at the moment...

Offline JOD

  • Hero Member
  • *****
  • Posts: 1973
  • Karma: +4/-0
Re: [_CODE_] SND - SMTP Notification Device (UPnP to SMTP bridge) V0.2
« Reply #12 on: May 29, 2011, 03:08:49 pm »
SND V0.2

Email Subject: "Message from Vera #12XXX"
Email Body: "Front door unlocked"

Instant email notifications. Love it.

JOD.

I'm sorry, my responses are limited. You must ask the right questions.

Offline denix

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1088
  • Karma: +1/-0
Re: [_CODE_] SND - SMTP Notification Device (UPnP to SMTP bridge) V0.2
« Reply #13 on: June 01, 2011, 12:02:48 am »
@Henk, you mentioned ADD, where I had the same issue:

http://forum.micasaverde.com/index.php?topic=5130.msg31677#msg31677
Veras (1, 2, 3, Lite, Plus), lots of different Z-Wave modules, Luup plugins and theater/security integration.

Offline Henk

  • Hero Member
  • *****
  • Posts: 820
  • Karma: +3/-0
Re: [_CODE_] SND - SMTP Notification Device (UPnP to SMTP bridge) V0.2
« Reply #14 on: June 01, 2011, 03:32:25 am »
@Henk, you mentioned ADD, where I had the same issue:

http://forum.micasaverde.com/index.php?topic=5130.msg31677#msg31677


@denix

Yes, and i solved it. In ADD comment out 2 lines using " --"
Here is the example:
Code: [Select]
 local SMTP_SERVER = "my.smtp.host"
-- local SMTP_AUTH_USER = ""
-- local SMTP_AUTH_PW = ""        
  local SMTP_PORT = "25"
  local USER_SENDING = "sender@my.vera"
  local USER_RECEIVING = "receiver@gmail.com"
« Last Edit: June 01, 2011, 06:33:37 am by Henk »
| Vera2 @ UI4 1.1.1350 / 3.20 | Vera Lite @ UI5 | Vera 3 @ UI5 | 2x Merten  504519 | 1x Duewi  064374 | 1x Everspring SM103 doorbell mod |1 Y-cam IP cam | various LUUP plugins |