Luup code to send your own email notifications

This is the result of a thread in “Setup and Usage” - simple code that works and instructions on its use:

local myEmail     = "your valid email (they check)"

local message_out = "OMG WTF it works!!"
local send_to     = myEmail
local sender      = myEmail
local subject_out = "Battery Low Notification"

local smtp = require("socket.smtp")

local mesgt    = {
      headers  = {
      to       = send_to,
      from     = sender,
      subject  = subject_out},
      body     = message_out}

local result   = smtp.send { 
      from     = sender,
      rcpt     =  {send_to},
      source   =  smtp.message(mesgt),
      server   = "smtp2go.com",
      port     = "2525",
      user     = myEmail,
      password = "verasmtp"}

It uses a “free” SMTP server, “free” as in 10 emails/day limit but how many do you need in one day at your house? :wink: There are also minimal fee higher plans.

Go to http://www.smtp2go.com/ to create a free account, use “verasmtp” as the password or change it in the code above. Your normal email address will be your user name which you also enter into the top line above.

Copy and paste the above code into a new scene, enter your email address after having signed up to smtp2go.com, save Luup code, save changes, click “Run Scene”, and it WILL WORK ;D

Change things to suit, it’s always easier to break code than make code…

Hope this helps,
bob

Great Idea! Could it be used as a notifier from my PC running Labview? Just curious.
Regards
Tim Alls
AllSeas Yachts

Hi Tim -

I’m not at all familiar with Labview. This code uses the Lua smtp.send function in your Vera so it executes in a Vera “scene”.

I’m sure Labview has a method of sending email via SMTP(?) in which case you could certainly use smtp2go.com as your sending relay if your own provider is picky about their SMTP (like gmail is!).

I’d be happy to help you further via a private message since this would evolve into a non-Vera solution and not for this forum.

bob

You know me…I will just copy the command from WireShark and paste into a TCPIP connection! So far that method has been working everytime!
Thanks
Tim

Nice job man…
I’m new in luup code, and if you can help i apreciated.
What are the parameters that i need use to secure smtp server (like gmail)???
Tks

[quote=“flanew, post:5, topic:168161”]Nice job man…
I’m new in luup code, and if you can help i apreciated.
What are the parameters that i need use to secure smtp server (like gmail)???
Tks[/quote]
As far as I know socket.smtp does not support secure servers like gmail yet, but I believe it is on the “get a round tuit” list.

As an alternative some are using a “free” smtp server - check my other thread on this topic at http://forum.micasaverde.com/index.php?topic=6169.msg39623#msg39623)
for details.

Hope that helps,
bob

Hi bob, help a lot
Thank you

Hi I realise this is an old thread but is it possible to use this code to attach a HTML file to an email?

Thanks,

Sam.

Based on this: LuaSocket: SMTP support, I’d say the answer is very likely yes. The bottom of that page shows how to send an image file - it looks like it would be possible to send html as well. But it will take a bit of coding.

Sorry for the delay - thought I’d already replied, yes that worked a treat thank you.
in case anybody else wants to do this I’ve attached the new section of code where:
var att = ‘filename.html’ (which is located in folder: /nas/ on my vera)
var subjectV = ‘subject of your email’
var emTo = ‘EmailAddress@ToBeSent.To’

[code]
local smtp = require(“socket.smtp”)
local mime = require(“mime”)
local ltn12 = require(“ltn12”)

source = smtp.message{
headers = {-- Remember that headers are ignored by smtp.send.
from = “John Doedonotreply@JohnDoe.YES”,
to = emTo,
subject = subjectV
},
body = {
[1] = {
headers = {
[“content-type”] = ‘text/html; name=“Email.html”’
},
body = mime.eol(0, content)
},
[2] = {
headers = {
[“content-type”] = ‘text/html; name="’…att…‘"’,
[“content-disposition”] = ‘attachment; filename="’…att…‘"’,
[“content-description”] = ‘Event Report’,
[“content-transfer-encoding”] = “BASE64”
},
body = ltn12.source.chain(
ltn12.source.file(
io.open(‘/nas’…att, “rb”)
),
ltn12.filter.chain(
mime.encode(“base64”),
mime.wrap()
)
)
}
}
}
– finally send it
r, e = smtp.send{
from = ‘YOUR-EMAIL-ADDRESS-YOU-SIGNED-UP-WITH@SMTP2GO’,
rcpt = emTo,
source = source,
server = “smtp2go.com”,
port = “2525”,
user = ‘SMTP2GO username’,
password = “SMTP2GO password”
}[/code]

Sam

I looking to install a Vera at my office and we have a local outgoing SMTP server on the LAN.
Can this code be modified to use that?

Yes, you probably could modify the code to point to your local server.

See also this thread where the SMTP plugin is described. This particular post has a version for UI7, the original was for UI5. I mainly use this on openLuup. http://forum.micasaverde.com/index.php/topic,11510.msg235692.html#msg235692