1

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

smtp = require("socket.smtp")

address = { "<someone@gmail.com>" }
from    = { "<someone@gmail.com>" }
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

user1709076
  • 2,538
  • 9
  • 38
  • 59

1 Answers1

1

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
}
Tom Studee
  • 10,316
  • 4
  • 38
  • 42
  • Hi, I am not running an smtp service. I tried following the directions here http://msdn.microsoft.com/en-us/library/8b83ac7t(v=vs.100).aspx but do not find an option to 'turn on smtp for IIS'. I only see 'FTP server', 'Web Management Tools' and 'World Wide Web Services'. (adding 'local' shouldn't matter - though i tried it - since 'local' just specifies the scope of the variable being 'local' or 'global'. Thanks for your response – user1709076 Jun 06 '13 at 21:05
  • Hi Tom, thanks again. We're getting closer. When I do 'ping mail.localhost.com' I get a response. When I do 'ping smtp.localhost.com' I also get a response. I've tried : r, e = smtp.send{ ..., server = "smtp.localhost.com", port = 25} and r, e = smtp.send{ ... , server = "mail.localhost.com", port = 25} - I am still getting 'connection refused' though. Many thanks – user1709076 Jun 10 '13 at 14:30
  • try the above, if that doesn't work try opening telnet 127.0.0.1 on port 25 and see if you are able to see a response – Tom Studee Jun 10 '13 at 14:46
  • Hi Tom, I tried smtp.send{... server = "127.0.0.1", port = 25}. When I do 'telnet localhost 25', I get 'Connecting to 127.0.0.1... Could not open connection to the host, on port 25: Connection failed' – user1709076 Jun 10 '13 at 18:31
  • @user1709076 that likely means there is not actually an smtp service running locally. you will need to set one up, or use the ip address of a machine which has one set up on it already. – Tom Studee Jun 10 '13 at 18:34
  • Do you have any advice on how to do that? I hear it is not as easy as using IIS to enable smtp, because smtp can only run on windows 7 if you are using an 'enterprise edition'? If I just send emails through my gmail account, https://kb.siteground.com/google_free_smtp_server/ by pointing my luascript at smtp.google.com and log-in with my username and passwrod is there any security threat that my password gets intercepted with that? – user1709076 Jun 10 '13 at 19:11
  • You could try running http://www.xmailserver.org/. However, if you are using TLS/SSL to authenticate to google that is secure enough that I wouldn't worry about it. – Tom Studee Jun 10 '13 at 20:13