Send mail through Lua

Asked

Viewed 211 times

3

I want to send a simple mail in Lua, I used the example in official documentation, and always give me back nil. Example:

-- load the smtp support
local smtp = require("socket.smtp")

from = "<[email protected]>"

rcpt = {
  "<[email protected]>",
  "<[email protected]>",
  "<[email protected]>"
}

mesgt = {
 headers = {
   to = "Fulano da Silva <[email protected]>",
   cc = '"Beltrano F. Nunes" <[email protected]>',
   subject = "My first message"
},
body = "I hope this works. If it does, I can send you another 1000  copies."
}

r, e = smtp.send{
 from = from,
 rcpt = rcpt, 
 source = smtp.message(mesgt)
}

Says:

host or service not provided, or not know

  • Doesn’t generate any errors? Enough to send? I think only this won’t really solve it. You need to set and authenticate on the server. This example only works if specific circumstance, it is not there to resolve any situation.

1 answer

4


Maybe this can help:

-- load the smtp support
local smtp = require("socket.smtp")

from = "<[email protected]>"

rcpt = {
  "<[email protected]>",
  "<[email protected]>",
  "<[email protected]>"
}

mesgt = {
 headers = {
   to = "Fulano da Silva <[email protected]>",
   cc = '"Beltrano F. Nunes" <[email protected]>',
   subject = "My first message"
},
body = "I hope this works. If it does, I can send you another 1000  copies."
}

r, e = smtp.send{
 from = from,
 rcpt = rcpt, 
 source = smtp.message(mesgt)
 user = "usuario_valido_em_algum_servidor_de_email_que+voce_tenha_acesso",
 password = "senhaqui",
 server = "servidor_smtp_onde_voce_tenha_acesso_smtp.google.com_por_exemplo",
 port = 465, -- pode ser outra porta
 create = sslCreate
}

I put in the Github for future reference.

I do not know if I would send it without encryption in this case. I do not know if this library is complete. She doesn’t say anything about SSL and without this protocol it will be difficult to use any server nowadays.

If you read the documentation, you will see that there are other things that need to be done. Just copying done example does not solve everything. You have to study existing material and adapt to what you need.

  • Thanks for the help, I have the following error when using the smtp server. It says "host or service not provided, or not know"

  • It’s exactly what I thought it was.

  • But both server, user and password data are correct.

  • I don’t know, you didn’t show it after all. But that’s what I said, there’s probably no SSL support in this library, so you’d have problems on almost every server.

  • Do not send, in the documentation do not meet, only with this code will not work.

  • I think it will not even, I think it does not support SSL and almost all servers require. See if you find some that does not require to take the test.

  • http://stackoverflow.com/questions/11070623/lua-send-mail-with-gmail-account. Maybe this can help.

  • If it helps you, great.

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.