Send mail via moon

2

I want to send a simple email on Lua, I used the example in official documentation , and returns me always 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)
}

It says:

  

host or service not provided, or not know

    
asked by anonymous 13.07.2015 / 17:56

1 answer

3

Maybe this might 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 do not know if it would be unencrypted in this case. I do not know if this library is complete. It does not 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 the ready sample does not solve everything. You have to study the existing material and adapt to what you need.

    
13.07.2015 / 18:11