lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


G'Day,

	I just have a couple of questions about the SMTP side of Lua Socket.
The first, and likely easiest, question relates to HTML emails.  I do
not really the specifics of how they are sent, but I believe there are
just some slight differences in the headers between a plain text email
and a HTML email.  As such, is it possible to send HTML emails with Lua
Socket?  If so, what are the additional lines required for a basic HTML
email?

	Secondly, while I have been able to successfully send regular emails
with Lua Socket, I have not yet managed to send an email with a simple
attachment.  The LED showing CPU activity glows almost the whole time,
but nothing ever happens --- I end up having to kill the script after
waiting several minutes.  I have copied my source below: I would imagine
I have made a simple error that can be quickly spotted by someone more
experienced.  If not, then any suggestions on how to debug this would be
greatly appreciated.

	-- Matthew

--begin source
#!/usr/local/bin/lua

smtp = require("socket.smtp")
mime = require("mime")
ltn12 = require("ltn12")

mailserv = "XXX"
mailport = "25"

from = "<XXX>"
rcpt = { "<XXX>", "<XXX>" }

mesgt =  smtp.message{
   headers = {
      to = "XXX",
      subject = "Test Lua Email"
   },
   body = {
      preable = "This email contains attachments.",
      [1] = {
	 body = mime.eol(0, [[
			       "With any luck, we are able to see a Lua-sent
			       email here."
			 ]])
      },
      [2] = {
	 headers = {
	    ["content-type"] = 'text/plain; name="smtp-test.lua"',
	    ["content-disposition"] = 'attachment; filename="smtp-test.lua"',
	    ["content-description"] = 'the send script\'s source',
	    ["content-transfer-encoding"] = "BASE64"
	 },
	 body = ltn12.source.chain(
				   ltn12.source.file(io.open("smtp-test.lua", "r")), 
				   ltn12.filter.chain(
						      mime.encode("base64"),
						      mime.wrap()
						   )
				)
      },
      epilogue = "A few words at the end..."
   }
}

r, e = smtp.send {
   from = from,
   rcpt = rcpt, 
   source = mesgt,
   server = mailserv,
   port = mailport
}

if (e) then
   io.stderr:write("Could not send email: ", e, "\n")
end
--end source