annotate website/src/examples/upload-and-email.html.luan @ 1824:92860f763715

smtpcorp change
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 19 Aug 2024 19:34:24 -0400
parents 0c46edec25dd
children 50e570b598b2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
693
ca169567ce07 module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents: 564
diff changeset
1 local Io = require "luan:Io.luan"
ca169567ce07 module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents: 564
diff changeset
2 local Http = require "luan:http/Http.luan"
ca169567ce07 module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents: 564
diff changeset
3 local Mail = require "luan:mail/Mail.luan"
564
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
1589
0c46edec25dd mail work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1576
diff changeset
6 local send = Mail.sender{
1259
e8020216dee7 add Luan.to_luan and fix multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1217
diff changeset
7 host = "smtpcorp.com"
1824
92860f763715 smtpcorp change
Franklin Schmidt <fschmidt@gmail.com>
parents: 1589
diff changeset
8 username = "luan"
92860f763715 smtpcorp change
Franklin Schmidt <fschmidt@gmail.com>
parents: 1589
diff changeset
9 password = "luanhost2"
1259
e8020216dee7 add Luan.to_luan and fix multipart/form-data
Franklin Schmidt <fschmidt@gmail.com>
parents: 1217
diff changeset
10 port = 2525
564
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 %>
1178
49cf706c326a serve_for_nginx on port 8081
Franklin Schmidt <fschmidt@gmail.com>
parents: 1152
diff changeset
15 <!doctype html>
564
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 <html>
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 <body>
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 <h1>Upload and Email</h1>
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 <form method="post" enctype="multipart/form-data">
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 <p>Email: <input name=email></p>
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 <p><input type=file name=file></p>
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 <p><input type=submit></p>
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 </form>
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 </body>
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 </html>
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 <%
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 end
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 local function sent()
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 %>
1178
49cf706c326a serve_for_nginx on port 8081
Franklin Schmidt <fschmidt@gmail.com>
parents: 1152
diff changeset
31 <!doctype html>
564
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 <html>
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 <body>
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 <h1>Upload and Email</h1>
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 <p>file sent</p>
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 </body>
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 </html>
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 end
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 return function()
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 Io.stdout = Http.response.text_writer()
1152
21d157b153fe change http parameters interface
Franklin Schmidt <fschmidt@gmail.com>
parents: 693
diff changeset
43 local email = Http.request.parameters.email
564
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 if email == nil then
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 form()
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 else
1152
21d157b153fe change http parameters interface
Franklin Schmidt <fschmidt@gmail.com>
parents: 693
diff changeset
47 local file = Http.request.parameters.file
564
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 send{
1589
0c46edec25dd mail work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1576
diff changeset
49 From = "smtp@luan.software"
0c46edec25dd mail work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1576
diff changeset
50 To = email
0c46edec25dd mail work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1576
diff changeset
51 Subject = "Upload and Email"
0c46edec25dd mail work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1576
diff changeset
52 body = {
0c46edec25dd mail work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1576
diff changeset
53 {
0c46edec25dd mail work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1576
diff changeset
54 body = "file should be attached"
0c46edec25dd mail work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1576
diff changeset
55 }
0c46edec25dd mail work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1576
diff changeset
56 {
0c46edec25dd mail work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1576
diff changeset
57 ["Content-Type"] = file.content_type
0c46edec25dd mail work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1576
diff changeset
58 ["Content-Disposition"] = [[attachment; filename="]]..file.filename..[["]]
0c46edec25dd mail work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1576
diff changeset
59 body = file.content
0c46edec25dd mail work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1576
diff changeset
60 }
0c46edec25dd mail work
Franklin Schmidt <fschmidt@gmail.com>
parents: 1576
diff changeset
61 }
564
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
62 }
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
63 sent()
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
64 end
c8d4d69c6dd4 add examples/upload-and-email.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
65 end