Mercurial Hosting > luan
annotate website/src/examples/upload-and-email.luan @ 594:e91e476186c7
theme indentation
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 03 Sep 2015 12:23:53 -0600 |
parents | c8d4d69c6dd4 |
children | ca169567ce07 |
rev | line source |
---|---|
564
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1 local Io = require "luan:Io" |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2 local Http = require "luan:http/Http" |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3 local Mail = require "luan:mail/Mail" |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4 |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5 |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
6 local send = Mail.Sender{ |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
7 host = "smtpcorp.com"; |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
8 username = "smtp@luanhost.com"; |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
9 password = "luanhost"; |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
10 port = 2525; |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
11 }.send |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
12 |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
13 local function form() |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
14 %> |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
15 <html> |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
16 <body> |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
17 <h1>Upload and Email</h1> |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
18 <form method="post" enctype="multipart/form-data"> |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
19 <p>Email: <input name=email></p> |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
20 <p><input type=file name=file></p> |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
21 <p><input type=submit></p> |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
22 </form> |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
23 </body> |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
24 </html> |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
25 <% |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
26 end |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
27 |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
28 local function sent() |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
29 %> |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
30 <html> |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
31 <body> |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
32 <h1>Upload and Email</h1> |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
33 <p>file sent</p> |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
34 </body> |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
35 </html> |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
36 <% |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
37 end |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
38 |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
39 return function() |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
40 Io.stdout = Http.response.text_writer() |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
41 local email = Http.request.parameter.email |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
42 if email == nil then |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
43 form() |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
44 else |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
45 local file = Http.request.parameter.file |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
46 send{ |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
47 from = "smtp@luanhost.com"; |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
48 to = email; |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
49 subject = "Upload and Email"; |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
50 body = "file should be attached"; |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
51 attachments = {file}; |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
52 } |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
53 sent() |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
54 end |
c8d4d69c6dd4
add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
55 end |