ex12.lua 1020 B

12345678910111213141516171819202122232425262728293031323334
  1. local smtp = require"socket.smtp"
  2. local mime = require"mime"
  3. local ltn12 = require"ltn12"
  4. CRLF = "\013\010"
  5. local message = smtp.message{
  6. headers = {
  7. from = "Sicrano <[email protected]>",
  8. to = "Fulano <[email protected]>",
  9. subject = "A message with an attachment"},
  10. body = {
  11. preamble = "Hope you can see the attachment" .. CRLF,
  12. [1] = {
  13. body = "Here is our logo" .. CRLF},
  14. [2] = {
  15. headers = {
  16. ["content-type"] = 'image/png; name="luasocket.png"',
  17. ["content-disposition"] =
  18. 'attachment; filename="luasocket.png"',
  19. ["content-description"] = 'LuaSocket logo',
  20. ["content-transfer-encoding"] = "BASE64"},
  21. body = ltn12.source.chain(
  22. ltn12.source.file(io.open("luasocket.png", "rb")),
  23. ltn12.filter.chain(
  24. mime.encode("base64"),
  25. mime.wrap()))}}}
  26. assert(smtp.send{
  27. rcpt = "<[email protected]>",
  28. from = "<[email protected]>",
  29. server = "localhost",
  30. port = 2525,
  31. source = message})