Plugin SMTP(S) Notification

New version : 0.92

Hi, All
A simple plugin for sending notification using your own SMTP(S) server.
I use a lot of informations/code previously published on this forum to create a plugin

[ul][li]SSL connexion to server[/li]
[li]Server Authentification[/li]
[li]Dynamic message body that can include value comming from other plugin variable[/li]
[li]Setup GUI[/li]
[li]Multiple eMail recipient (TODO)[/li]
[li]CC/BCC (TODO)[/li]
[li]Add serial of sending Unit to subject[/li][/ul]

Tested only with UI5 (1.5.408)


[ul][li]0.5 Initial public release[/li]
[li]0.6 Minor UI correction / Add new option for adding Vera Serial number to Subject[/li]
[li]0.7 UI modification, add a setup Tab to simplify Setup[/li]
[li]0.8 Test / Debug Release not published[/li]
[li]0.9 UI Modification, Add Function to reset #Mail sent, BugFix [/li]
[li]0.92 BugFix, correct smtp syntax problem that block gmail usage, add ability to add sender name in action.[/li][/ul]

Automatic Installation version may be older due to validation Delay


Upload the plugin files :

  • In the Apps section open Develop Apps >> Luup Files and upload all the files you downloaded. check the Restart Luup after upload checkbox and click GO.

Create the SMTP Interface Device:

  • Open Create Device.
  • In the UpnpDevFilename input box enter D_SmtpNotification.xml
  • In the Upnp Implementation Filename input box enter I_SmtpNotification.xml
  • In the Description input box enter a name for the panel device, e.g. My eMail Notification.
  • Click Create device.
  • Close this window and Save.

Go to the SMTP Tab and Fill the required parameters. Parameters in bold are mandatory.

Advanced Configuration
In the device advanced tab, you can find the following parameters (See screenshot)

[ul][li]Last Error message with readable time[/li]
[li]Your SMTP server address or name[/li]
[li]SMTP server port (Note SMTPS always use port 465)[/li]
[li]Add Vera serial to subject[/li]
[li]Activate server authentication[/li]
[li]User name used for authentication[/li]
[li]Password used for authentication[/li]
[li]Activate SSL (SMTPS)[/li]
[li]Address used for sending eMail[/li]
[li]Description (name) used for sending eMail[/li]
[li]Number of mail correctly sent[/li]
[li]Timestamp of last Error[/li]
[li]Timestamp of last successful send[/li]
[li]Debug Flag[/li][/ul]

  • Close this window and Save then Reload Luup

[size=10pt]USAGE IN SCENE[/size]

SendEmail action

[li]Recipient eMail(Only one for now)[/li]
[li]Recipient Name[/li]

SendDynamicEmail action
The idea behind that is to be able to send an eMail with a variable part coming from another device value e.g. :
Where the value 18 is coming from other device,. You can see below how to setup this dynamic message body

Warning Only ([b]18[/b]%) of battery remaining

[td]PreMessage ==>[/td]
[td]“Warning Only (”[/td]
[td]DeviceID ==>[/td]
[td]Your device number[/td]
[td]Devicetype =>[/td]
[td]VariableName =>[/td]
[td]PostMessage =>[/td]
[td]“%) of battery remaining”[/td]

[li]Recipient eMail (Only one for now)[/li]
[li]Recipient Name[/li]
[li]PreMessage Beginning of message body[/li]
[li]PostMessage End of message body[/li]
[li]DeviceID Id of device used for variable part[/li]
[li]Devicetype Type of device used for variable part[/li]
[li]VariableName Variable of device used for variable part[/li][/ul]

ResetCount Action
Reset number of # message(s) sent

[size=10pt]USAGE IN CODE[/size]
Assuming that the Plugin was installed as Device 99, the following tests should work. Your installation will have a different Device number, please adjust accordingly.

luup.call_action("urn:upnp-org:serviceId:SmtpNotification1", "SendEmail", { Recipient_Name="Tony Stark", Recipient_eMail="", Subject= "Title", Message="Message" }, 99)

luup.call_action("urn:upnp-org:serviceId:SmtpNotification1", "ResetCount",{}, 99)

Great! As a plugin this should get a lot more use.

Hello Massalia,

Welcome and talk about hitting the road running.
Well done and this is will no doubt find it way on to a lot of user’s unit.
Just tested and I didn’t encounter any real issues.
Feedback: Status message remains at sending mail which is misleading.
Either update to message sent at time or clear message after n time or both.
Potential to write error message…
Noting, I this may not be seen unless they are in the UI.

[quote=“Brientim, post:3, topic:172374”]Hello Massalia,

Feedback: Status message remains at sending mail which is misleading.
Either update to message sent at time or clear message after n time or both.
Potential to write error message…
Noting, I this may not be seen unless they are in the UI.[/quote]

Thanks for your feedback, but i don’t really understand your remark (probably because of my poor english)
Do you talk about the message that is visible on the dashboard ?

Because normally this messsage display the last status, and it’s updated at each mail sending, so if you send a “wrong” message the error will stay until the next “good” send.
I only test my plugins on UI5, do you use it from other version ?

You can have three “states” (Screenshot attached)

[ul][li]RST - When the plugin start[/li]
[li]OK - When the last message was successfully sent[/li]
[li] - When the last message was not sent or sent with error(s)[/li][/ul]

Hi Massalia,

I was referring to the System Status messages which are reporting as part of your trace function.

@Brientim Ok thanks, some debug Stuff still visible ;D

I’ll change this in next release, it’s useless.

New Version 0.6

Upgrade :

  • Minor update on interface state : Remove useless UI message in System Status
  • Add Option to automaticaly append Vera Serial Number to subject. (For people with multiple box)

Update is available in first post

New version 0.7 just published with new GUI improvment for setup.

See first post for details, and roadmap.

One thing that might save you some work is to build a string formatter, and “teach” it to perform substitutions.

Then, instead of gluing strings together in fixed ways, users could choose exactly what appears (and where) within both the Subject, and Body, of the messages sent.

This is fairly common for i18n/l10n in various languages so you’ve probably seen it before, but something like:
[tt] This is the subject for {} alert at {timestamp.short}[/tt]
or a Body like
[tt] An event occurred at {timestamp.long} on {device.title}. Please contact {email}[/tt]

etc. Over time, more complex expressions could be added to the system without needing to add any more stateVars to the plugin itself.

eg. references for number/date formatting
eg. references to attrs or state vars from other devices

Anyhow, just a thought…

A string substitution (à la @guessed’s suggestion) that I currently do is notifications from my security system.

{devicename} armed by {urn:micasaverde-com:serviceId:AlarmPartiton2|LastUser}

The template syntax is made up, but that’s a real-world example. Currently I do this with custom Lua, of course.

Great plugin idea, by the way.

Edit: I accidentally a verb in the first sentence.

@guessed, @futzle

Thanks for your idea and your feedback, but this function will require a lot of work :wink:

The idea behind the DynamicSend action is just to offer a step between, a complex LUA script with lot of complexity and flexibility and a plugin only usage with simple fixed message only.

I’ll first finish the remaining planed functions before, but if there is a known source for a working string parser writen in LUA i 'd like to know where.


Below is a little bit of code I just slapped together to test the waters. It’s been built independent of Vera, so I can cleanly test the output formatting stuff, but it would be easy to put inside a Plugin.

It supports “substituting” two values into the string output. The first is “[tt]pi[/tt]”, where it can lay down the normal [clipped] value. The second is “[tt]currentTime[/tt]”, which emits the current time value.

The code supports rudimentary output formatting for numbers and dates using the built-in Lua-based formatters for the same. The output of running the below Lua code in the interpreter is also listed below to give you a sense for what it does.

It should be fairly easy to add “syntax” similar to what @futzle has listed above, and translate these into the corresponding [tt]luup.variable_get(…)[/tt] calls. Initially you could simply expand the if-ladder. Over time, something more functional could be added (mostly when there are lots of commands)

So far, I’ve used a Java-like format model, so the strings to be substituted look like:
[tt] {currentTime}

[code]local function formatString(value, format)
return value

local function formatNumber(value, format)
if (format == nil) then
return value
return format:format(value)

local function formatDate(value, format)
return, value)

local function formatValue(param)
local value, dataType, format = param:match(“([a-zA-Z0-9.:]+),(%a+),(.+)”)

if (value == nil) then
    value, dataType = param:match("([a-zA-Z0-9\.:]+),(%a+)")

    if (value == nil) then
        value = param:match("([a-zA-Z0-9\.:]+)")
        dataType = 'String'

        if (value == nil) then
            return string.format("{%s}", param)

if (value == 'currentTime') then
    value = os.time()
elseif (value == 'pi') then
    value = "3.141592654" -- more or less
    return string.format("{%s}", param)

if (dataType == 'Date') then
    return formatDate(value, format)
elseif (dataType == 'Number') then
    return formatNumber(value, format)
elseif (dataType == 'String') then
    return formatString(value, format)
    return 'INVALID'

return '**' .. param .. '**'


result = string.gsub(“Number values we dont understand {5.5}, {5.5,Number}, {5.5,Number,%10.4f}\nNumber values we understand {pi}, {pi,Number}, {pi,Number,%10.3f}\nString values we dont understand {title}\nDates we understand {currentTime}, {currentTime,Date}, {currentTime,Date,%x}\n”, “{(.-)}”, formatValue)


Number values we dont understand {5.5}, {5.5,Number}, {5.5,Number,%10.4f} Number values we understand 3.141592654, 3.141592654, 3.142 String values we dont understand {title} Dates we understand 1345323379, Sat Aug 18 13:56:19 2012, 08/18/12

Templating is something that ideally could be used by many different plugins, not just Massalia’s. It’d be great if we collectively found a way for plugins to share this code so that authors of plugins could just use it. A pity that doesn’t make this easy.

I agree. We can evolve this as a Lua library, if we can keep it generic enough, and then lobby to get it included in the base bundle (like the original intent of the stuff under Generic Lua Utilities). In this case we probably need work in both the command structure as well as the formatting stuff (I used the [tt]printf[/tt] and [tt]strftime[/tt] formats for simplicity, but these aren’t always easy for users)

If you’re interested, we can break this [library] discussion out into a separate thread.

Let’s continue templating talk here.

Plugin now validated, you can now install it directly from your Vera.

See first post for link.

Hello Massalia

Great plugin! I will probably use it a lot in my scenes, but one question?

If I install the plugin using Automatic installation procedure (APPS/Install apps) I got always error message in System Status area: eMail Notification: Lua error. Despite this I can send eMails.

If I upload plugin files to Vera and create device manually (according to your instructions) then it works without any error messages. (Then plugin is not visible in My apps page and probably auto update didn’t work.)

Do you know why automatic installation is causing that error and can I fix it?

(Vera3 with firmware 1.5.408, same error also in my Vera2 1.5.408 box)

quote=“Jukka, post:17, topic:172374”
Do you know why automatic installation is causing that error and can I fix it? [/quote]

BTW I get same error (Frenchized on my own) on my Vera3 UI5 1.5.408 as well :slight_smile:

@kiwi, @jukka

Thanks for your feedback I find the problem, but i need some help to solve it.
The automatic installation try to load a file that no longer exist in the last versions.

It does not affect the plugin behavior except for this error message.

As a temporary Fix, just manually upload the file smtps.lua, then restart luup engine.

Hello Massalia

Thanks for the fix. Now it seems to be working. First I had some problems, “lua” and Z-Wave was contantly restarting and the unit was busy all the time. But after few boots (power off) it starts to work.

I will test it more tomorrow, now it is midnight here…