Search code examples
luasmtpluasocket

LuaSocket smtp connection refused


I am wanting to send an email to a gmail account from lua using the socket library.

smtp = require("socket.smtp")

address = { "<[email protected]>" }
from    = { "<[email protected]>" }
theMessage = {
 headers = {
   to = "YOU",
   cc = '"him" ',
   subject = "I got something to tell you..."
 },
 body = "You're the best."
}
r, e = smtp.send{ from = from, rcpt = address, source = smtp.message(theMessage)}

When I do print(e)

"connection refused".

 print(r)

nil Any ideas?

I'm just following instructions from the site: http://w3.impa.br/~diego/software/luasocket/smtp.html


Solution

  • You may need to specify the ip/port in your smtp.send function

    smtp.send{ 
        from = from, 
        rcpt = address, 
        source = smtp.message(theMessage),
        server = 127.0.0.1,
        port   = 25
    }