Author Topic: Luup code to send your own email notifications  (Read 7862 times)

Offline FlyBoyBob

  • Full Member
  • ***
  • Posts: 163
  • Karma: +0/-0
Luup code to send your own email notifications
« on: April 18, 2011, 10:19:22 am »
This is the result of a thread in "Setup and Usage" - simple code that works and instructions on its use:

Code: [Select]
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?  ;) 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

Offline TimAlls

  • Hero Member
  • *****
  • Posts: 722
  • Karma: +0/-0
    • AllSeas Yachts
Re: Luup code to send your own email notifications
« Reply #1 on: April 18, 2011, 01:54:42 pm »
Great Idea! Could it be used as a notifier from my PC running Labview? Just curious.
Regards
Tim Alls
AllSeas Yachts

Offline FlyBoyBob

  • Full Member
  • ***
  • Posts: 163
  • Karma: +0/-0
Re: Luup code to send your own email notifications
« Reply #2 on: April 18, 2011, 02:04:33 pm »
Great Idea! Could it be used as a notifier from my PC running Labview? Just curious.
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

Offline TimAlls

  • Hero Member
  • *****
  • Posts: 722
  • Karma: +0/-0
    • AllSeas Yachts
Re: Luup code to send your own email notifications
« Reply #3 on: April 18, 2011, 03:27:46 pm »
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

Offline flanew

  • Newbie
  • *
  • Posts: 11
  • Karma: +0/-0
Re: Luup code to send your own email notifications
« Reply #4 on: May 10, 2011, 11:56:04 pm »
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

Offline FlyBoyBob

  • Full Member
  • ***
  • Posts: 163
  • Karma: +0/-0
Re: Luup code to send your own email notifications
« Reply #5 on: May 11, 2011, 07:56:49 am »
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
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

Offline flanew

  • Newbie
  • *
  • Posts: 11
  • Karma: +0/-0
Re: Luup code to send your own email notifications
« Reply #6 on: May 11, 2011, 08:45:08 pm »
Hi bob, help a lot
Thank you

Offline samyoue

  • Sr. Newbie
  • *
  • Posts: 28
  • Karma: +1/-0
Re: Luup code to send your own email notifications
« Reply #7 on: October 11, 2017, 08:36:03 pm »
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.

Offline jswim788

  • Hero Member
  • *****
  • Posts: 540
  • Karma: +30/-2
Re: Luup code to send your own email notifications
« Reply #8 on: October 11, 2017, 10:56:36 pm »
Based on this: http://w3.impa.br/~diego/software/luasocket/smtp.html, 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.