Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. local smtp = require("socket.smtp")
  2. local mime = require("mime")
  3. local ltn12 = require("ltn12")
  4. rcpt = {
  5. "exemplo@exemplo.com"
  6. }
  7.  
  8. mesgt = {
  9. headers = {
  10. ["content-type"] = 'text/html; charset="ISO-8859-1"',
  11. ["content-transfer-encoding"] = 'quoted-printable',
  12. to = "exepmo <"exemplo@exemplo.com">",
  13. ["content-type"] = 'image/png; name="image.png"',
  14. ["content-disposition"] = 'attachment; filename="image.png"',
  15. ["content-description"] = 'a beautiful image',
  16. ["content-transfer-encoding"] = "BASE64"
  17. subject = sujet
  18. },
  19.  
  20. body = "texto texto texto",
  21. [1] = {
  22.  
  23. body = ltn12.source.chain(
  24. ltn12.source.file(io.open("image.png", "rb")),
  25. ltn12.filter.chain(
  26. mime.encode("base64"),
  27. mime.wrap()
  28. )
  29. )
  30.  
  31. }
  32. }
  33. r, e = smtp.send{
  34. from = from,
  35. rcpt = rcpt,
  36. source = smtp.message(mesgt),
  37. port = 21,
  38. server = servidordemail
  39. }
  40.  
  41. headers = {
  42. -- Remember that headers are *ignored* by smtp.send.
  43. from = "Sicrano de Oliveira <sicrano@example.com>",
  44. to = "Fulano da Silva <fulano@example.com>",
  45. subject = "Here is a message with attachments"
  46. },
  47. body = {
  48. preamble = "If your client doesn't understand attachments, rn" ..
  49. "it will still display the preamble and the epilogue.rn" ..
  50. "Preamble will probably appear even in a MIME enabled client.",
  51. -- first part: no headers means plain text, us-ascii.
  52. -- The mime.eol low-level filter normalizes end-of-line markers.
  53. [1] = {
  54. body = mime.eol(0, [[
  55. Lines in a message body should always end with CRLF.
  56. The smtp module will *NOT* perform translation. However, the
  57. send function *DOES* perform SMTP stuffing, whereas the message
  58. function does *NOT*.
  59. ]])
  60. },
  61. -- second part: headers describe content to be a png image,
  62. -- sent under the base64 transfer content encoding.
  63. -- notice that nothing happens until the message is actually sent.
  64. -- small chunks are loaded into memory right before transmission and
  65. -- translation happens on the fly.
  66. [2] = {
  67. headers = {
  68. ["content-type"] = 'image/png; name="image.png"',
  69. ["content-disposition"] = 'attachment; filename="image.png"',
  70. ["content-description"] = 'a beautiful image',
  71. ["content-transfer-encoding"] = "BASE64"
  72. },
  73. body = ltn12.source.chain(
  74. ltn12.source.file(io.open("image.png", "rb")),
  75. ltn12.filter.chain(
  76. mime.encode("base64"),
  77. mime.wrap()
  78. )
  79. )
  80. },
  81. epilogue = "This might also show up, but after the attachments"
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement