We have moved at community.getvera.com

Author Topic: One way to send email through a server requiring Authentication through Lua  (Read 2184 times)

Offline mysticjay

  • Full Member
  • ***
  • Posts: 184
  • Karma: +1/-1
1. Lua dont support Mail servers requiring authentication (acts weird and does not support SSL)

2. For this you would need a local webserver to  actually send the email - then use the following code in your scene

3. Mios will stop Notifying you, after you reach your Quota limit for the day

4. If there are other ways to accomplish this, please share.... :)

Code: [Select]
--Lua code to send email by requesting HTTP GET

function url_encode(str)
  if (str) then
    str = string.gsub (str, "\n", "\r\n")
    str = string.gsub (str, "([^%w ])",
        function (c) return string.format ("%%%02X", string.byte(c)) end)
    str = string.gsub (str, " ", "+")
  end
  return str
end

function send_email(subject, body)
local http =  require("socket.http")
local b, h, c, e = http.request{ url = "http://localwebserver/mail.aspx?key=somekey&subject=" .. url_encode(subject) .. "&body=" ..url_encode(body) }
end


function send_motion_trip()
send_email("Jay Home - Motion Detecter Notification", "Garage Motion Detecter was Tripped on " .. os.date("%A %c"))
end


send_motion_trip()



Your local webserver depending on what you're running could use something like this....(This is in .NET, but could be in PERL or anything that supports mail servers requiring authentication)

Code: [Select]

   
            If  Request.QueryString("key")<> "yoursecretkey" Then Exit Sub

            Dim SmtpServer As New SmtpClient()
            SmtpServer.Credentials = New Net.NetworkCredential("username@dmomain.com", "password")
            SmtpServer.Host = "server.needing.authentication.com"
            Dim mail As New MailMessage()
            mail.From = New MailAddress("user@domain.com")
            mail.To.Add("user@domain.com")
            mail.Subject =  Request.QueryString("subject")
            mail.Body = Request.QueryString("body")
            SmtpServer.Send(mail)
« Last Edit: October 26, 2011, 08:50:05 pm by mysticjay »
Vera 2 (1.1.1338), Trane TZEMT400BB3,ML IWD600S(2), ML IWS1000S(2) , FI8905W, Aeon DSB04100-ZWUS, GE 45609(2), GE 45606(2), GE 45608, GE 45614 (5), LFM-20(2), Kwikset 99100-011 (5) , Hawking HRMD1, Droid X and Xoom as Remotes, Harmony Link