[_CODE_] SND - SMTP Notification Device (UPnP to SMTP bridge) V0.3a

EOL, unsupported.

Installation:

[ul][li]http://wiki.micasaverde.com/index.php/Install_LUUP_Plugins[/li]
[li]Set the variables [tt]SMTPServer, SMTPAuthUser, SMTPAuthPassword, SMTPPort, UserSending, UserReceiving [/tt] and restart the Lua engine.[/li][/ul]

Usage:

[ul][li][tt]luup.call_action( “urn:upnp-ap15e-com:serviceId:SND1”, “SendMail”, { subject = ‘Message from Vera’, body = ‘How are you today?’ }, 11 )[/tt]
replace [tt]11[/tt] with the SND device ID.[/li][/ul]

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

Remarks:

[ul][li]RFC 2821 requires all lines of the message body to end with CRLF.[/li][/ul]

Download:
[tt]https://docs.google.com/open?id=0Bz4omZm4gYcsNWM0MDc5MDQtMzI3OC00YjA3LThkMTUtYTlmNWVlMWY2YTg4[/tt]

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?

@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.

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).

[quote=“JOD, post:3, topic:168408”]@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.[/quote]

@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

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?

SND V0.2 is available. Syntax has changed, see topmost post.

Nice; thanks! Works.

F/R: Prowl integration, or the PND cousin of this. :slight_smile:
(I guess @axill’s earlier work may be a reference.)

@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.

  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.

YESSS!!!

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

--- 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:

--  <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?

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?

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.

SND V0.2

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

Instant email notifications. Love it.

JOD.

@Henk, you mentioned ADD, where I had the same issue:

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

[quote=“denix, post:14, topic:168408”]@Henk, you mentioned ADD, where I had the same issue:

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

@denix

Yes, and i solved it. In ADD comment out 2 lines using " --"
Here is the example:

  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"

Does it work with Gmail smtp ?

I havent seen anyone post here that got Gmail to work on port 443 with SSL enabled.
Maybe i didnt look hard enough through the threads?

I got as far as
http://forum.micasaverde.com/index.php?PHPSESSID=3051091f7ca575ea0b5fa4154e82da97&topic=6309.msg40295#msg40295

Anyone found something that proves the contrary?

[quote=“Henk, post:15, topic:168408”][quote=“denix, post:14, topic:168408”]@Henk, you mentioned ADD, where I had the same issue:

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

@denix

Yes, and i solved it. In ADD comment out 2 lines using " --"
Here is the example:

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" [/quote]

I’m surprised it worked for you - I needed to patch the code (attached under provided link) for that to work…

@denix,
For SND @Henk did comment out the parts in the smtp.send() call (as well). And although not stated as such here, the same may be true for ADD, per @huogas’ and @Henk’s comments over there based on your findings.

Hi,
it seems that SND isn’t Ui5 compatible at all. The messages text on the device in the dashboard have dissapeared.

Same thing for home made plugins, normal ?

gilles

Sent from my GT-I9000