Mercurial Hosting > luan
comparison website/src/examples/upload-and-email.html.luan @ 1217:4c2972f4d862
.html in examples
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Tue, 20 Mar 2018 15:43:16 -0600 |
| parents | website/src/examples/upload-and-email.luan@49cf706c326a |
| children | e8020216dee7 |
comparison
equal
deleted
inserted
replaced
| 1216:5dbb552075ff | 1217:4c2972f4d862 |
|---|---|
| 1 local Io = require "luan:Io.luan" | |
| 2 local Http = require "luan:http/Http.luan" | |
| 3 local Mail = require "luan:mail/Mail.luan" | |
| 4 | |
| 5 | |
| 6 local send = Mail.Sender{ | |
| 7 host = "smtpcorp.com"; | |
| 8 username = "smtp@luanhost.com"; | |
| 9 password = "luanhost"; | |
| 10 port = 2525; | |
| 11 }.send | |
| 12 | |
| 13 local function form() | |
| 14 %> | |
| 15 <!doctype html> | |
| 16 <html> | |
| 17 <body> | |
| 18 <h1>Upload and Email</h1> | |
| 19 <form method="post" enctype="multipart/form-data"> | |
| 20 <p>Email: <input name=email></p> | |
| 21 <p><input type=file name=file></p> | |
| 22 <p><input type=submit></p> | |
| 23 </form> | |
| 24 </body> | |
| 25 </html> | |
| 26 <% | |
| 27 end | |
| 28 | |
| 29 local function sent() | |
| 30 %> | |
| 31 <!doctype html> | |
| 32 <html> | |
| 33 <body> | |
| 34 <h1>Upload and Email</h1> | |
| 35 <p>file sent</p> | |
| 36 </body> | |
| 37 </html> | |
| 38 <% | |
| 39 end | |
| 40 | |
| 41 return function() | |
| 42 Io.stdout = Http.response.text_writer() | |
| 43 local email = Http.request.parameters.email | |
| 44 if email == nil then | |
| 45 form() | |
| 46 else | |
| 47 local file = Http.request.parameters.file | |
| 48 send{ | |
| 49 from = "smtp@luanhost.com"; | |
| 50 to = email; | |
| 51 subject = "Upload and Email"; | |
| 52 body = "file should be attached"; | |
| 53 attachments = {file}; | |
| 54 } | |
| 55 sent() | |
| 56 end | |
| 57 end |
