Mercurial Hosting > luan
changeset 564:c8d4d69c6dd4
add examples/upload-and-email.luan
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 04 Jul 2015 20:57:24 -0600 |
parents | 195a64f948f2 |
children | 22bfd8a2eaee |
files | website/src/examples/upload-and-email.luan |
diffstat | 1 files changed, 55 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/website/src/examples/upload-and-email.luan Sat Jul 04 20:57:24 2015 -0600 @@ -0,0 +1,55 @@ +local Io = require "luan:Io" +local Http = require "luan:http/Http" +local Mail = require "luan:mail/Mail" + + +local send = Mail.Sender{ + host = "smtpcorp.com"; + username = "smtp@luanhost.com"; + password = "luanhost"; + port = 2525; +}.send + +local function form() +%> +<html> + <body> + <h1>Upload and Email</h1> + <form method="post" enctype="multipart/form-data"> + <p>Email: <input name=email></p> + <p><input type=file name=file></p> + <p><input type=submit></p> + </form> + </body> +</html> +<% +end + +local function sent() +%> +<html> + <body> + <h1>Upload and Email</h1> + <p>file sent</p> + </body> +</html> +<% +end + +return function() + Io.stdout = Http.response.text_writer() + local email = Http.request.parameter.email + if email == nil then + form() + else + local file = Http.request.parameter.file + send{ + from = "smtp@luanhost.com"; + to = email; + subject = "Upload and Email"; + body = "file should be attached"; + attachments = {file}; + } + sent() + end +end