diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/website/src/examples/upload-and-email.html.luan	Tue Mar 20 15:43:16 2018 -0600
@@ -0,0 +1,57 @@
+local Io = require "luan:Io.luan"
+local Http = require "luan:http/Http.luan"
+local Mail = require "luan:mail/Mail.luan"
+
+
+local send = Mail.Sender{
+	host = "smtpcorp.com";
+	username = "smtp@luanhost.com";
+	password = "luanhost";
+	port = 2525;
+}.send
+
+local function form()
+%>
+<!doctype html>
+<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()
+%>
+<!doctype html>
+<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.parameters.email
+	if email == nil then
+		form()
+	else
+		local file = Http.request.parameters.file
+		send{
+			from = "smtp@luanhost.com";
+			to = email;
+			subject = "Upload and Email";
+			body = "file should be attached";
+			attachments = {file};
+		}
+		sent()
+	end
+end