12345678910111213141516171819202122232425262728293031323334 |
- local smtp = require"socket.smtp"
- local mime = require"mime"
- local ltn12 = require"ltn12"
- CRLF = "\013\010"
- local message = smtp.message{
- headers = {
- from = "Sicrano <[email protected]>",
- to = "Fulano <[email protected]>",
- subject = "A message with an attachment"},
- body = {
- preamble = "Hope you can see the attachment" .. CRLF,
- [1] = {
- body = "Here is our logo" .. CRLF},
- [2] = {
- headers = {
- ["content-type"] = 'image/png; name="luasocket.png"',
- ["content-disposition"] =
- 'attachment; filename="luasocket.png"',
- ["content-description"] = 'LuaSocket logo',
- ["content-transfer-encoding"] = "BASE64"},
- body = ltn12.source.chain(
- ltn12.source.file(io.open("luasocket.png", "rb")),
- ltn12.filter.chain(
- mime.encode("base64"),
- mime.wrap()))}}}
- assert(smtp.send{
- rcpt = "<[email protected]>",
- from = "<[email protected]>",
- server = "localhost",
- port = 2525,
- source = message})
|