comparison website/src/examples/upload-and-email.luan @ 564:c8d4d69c6dd4

add examples/upload-and-email.luan
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 04 Jul 2015 20:57:24 -0600
parents
children ca169567ce07
comparison
equal deleted inserted replaced
563:195a64f948f2 564:c8d4d69c6dd4
1 local Io = require "luan:Io"
2 local Http = require "luan:http/Http"
3 local Mail = require "luan:mail/Mail"
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 <html>
16 <body>
17 <h1>Upload and Email</h1>
18 <form method="post" enctype="multipart/form-data">
19 <p>Email: <input name=email></p>
20 <p><input type=file name=file></p>
21 <p><input type=submit></p>
22 </form>
23 </body>
24 </html>
25 <%
26 end
27
28 local function sent()
29 %>
30 <html>
31 <body>
32 <h1>Upload and Email</h1>
33 <p>file sent</p>
34 </body>
35 </html>
36 <%
37 end
38
39 return function()
40 Io.stdout = Http.response.text_writer()
41 local email = Http.request.parameter.email
42 if email == nil then
43 form()
44 else
45 local file = Http.request.parameter.file
46 send{
47 from = "smtp@luanhost.com";
48 to = email;
49 subject = "Upload and Email";
50 body = "file should be attached";
51 attachments = {file};
52 }
53 sent()
54 end
55 end