Sending EMAIL (adv)

No replies
brett
Offline
Providence, United States
Joined: 9 Jan 2010

This set of scripts show how to send an email encoded as a MIME type so you can transmit HTML email.

In this example we use a simplistic template engine (lte.lua) that uses LUA, naturally, as its scripting language.  The template understand the following tokens.

  • {{ }}  - Will import a value into the output stream
  • {% %} - execute a LUA code fragment
  • {> >} - output the contents with HTML escape characters.

Here is what our TEMPLATE (relay.tmpl) looks like:

<h1>Relay event</h1>
{%
 state = f:getValue("output.state","state")
 if state == "on" then color = "green" else color = "red" end
 id = f:getValue("xap-header","source"):sub(-1)
%}
The relay {{id}} is <font color="{{color}}">{{state}}</font>

The event was
<pre>
{{ tostring(f) }}
</pre>

and here are some emails that will be generated by this template and the attached Applet

Relay event on email message

Relay Event off

you will need to tweak this sample and adjust for your own username, password, SMTP server,  Port and email addresses. Normally SMTP will use port 25 my provider likes to be tricky so you'll see in the script 2525.

The LTE script is not an applet but is required to placed into the /etc/plugboard directory. This is the TEMPLATE engine and I refactored it out of the applet so it could be reused and understood seperately.

Enjoy,

Brett

AttachmentSize
lte.lua1.57 KB
relay.tmpl288 bytes
htmlEmailApplet.lua1.24 KB
Hardware Info