view website/src/examples/upload-and-email.luan @ 745:9c1f28b26395

a uri can now write another uri which copies the content
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 13 Jul 2016 21:27:23 -0600
parents ca169567ce07
children 21d157b153fe
line wrap: on
line source

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()
%>
<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()
%>
<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.parameter.email
	if email == nil then
		form()
	else
		local file = Http.request.parameter.file
		send{
			from = "smtp@luanhost.com";
			to = email;
			subject = "Upload and Email";
			body = "file should be attached";
			attachments = {file};
		}
		sent()
	end
end