One way to send email through a server requiring Authentication through Lua

  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… :slight_smile:

--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)


    
            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)