aboutsummaryrefslogtreecommitdiff
path: root/gem/ex12.lua
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2007-10-11 21:16:28 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2007-10-11 21:16:28 +0000
commit52ac60af8132ae7e42151d3012a9607d7cadaf95 (patch)
tree95085f9f535d20b6686399af1ba284bb74ac89d3 /gem/ex12.lua
parente394956cde629e24ecdd285c4c13c206891fcec4 (diff)
downloadluasocket-52ac60af8132ae7e42151d3012a9607d7cadaf95.tar.gz
luasocket-52ac60af8132ae7e42151d3012a9607d7cadaf95.tar.bz2
luasocket-52ac60af8132ae7e42151d3012a9607d7cadaf95.zip
Tested each sample.
Diffstat (limited to 'gem/ex12.lua')
-rw-r--r--gem/ex12.lua34
1 files changed, 34 insertions, 0 deletions
diff --git a/gem/ex12.lua b/gem/ex12.lua
new file mode 100644
index 0000000..de17d76
--- /dev/null
+++ b/gem/ex12.lua
@@ -0,0 +1,34 @@
1local smtp = require"socket.smtp"
2local mime = require"mime"
3local ltn12 = require"ltn12"
4
5CRLF = "\013\010"
6
7local message = smtp.message{
8 headers = {
9 from = "Sicrano <sicrano@example.com>",
10 to = "Fulano <fulano@example.com>",
11 subject = "A message with an attachment"},
12 body = {
13 preamble = "Hope you can see the attachment" .. CRLF,
14 [1] = {
15 body = "Here is our logo" .. CRLF},
16 [2] = {
17 headers = {
18 ["content-type"] = 'image/png; name="luasocket.png"',
19 ["content-disposition"] =
20 'attachment; filename="luasocket.png"',
21 ["content-description"] = 'LuaSocket logo',
22 ["content-transfer-encoding"] = "BASE64"},
23 body = ltn12.source.chain(
24 ltn12.source.file(io.open("luasocket.png", "rb")),
25 ltn12.filter.chain(
26 mime.encode("base64"),
27 mime.wrap()))}}}
28
29assert(smtp.send{
30 rcpt = "<diego@cs.princeton.edu>",
31 from = "<diego@cs.princeton.edu>",
32 server = "localhost",
33 port = 2525,
34 source = message})