This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

email?
#1
I am using the standard script to send email. LM5 v20191015.

No matter what host I set in server, I get an error about "string: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8  https://support.google.com/mail/?p=BadCredentials c5sm15367699wrs.73 - gsmtp"


Why on earth would GOOGLE be there if I ask it to go to "sss" ???

How can I debug this?
I have tried all the combination of 'secure' found on the forum in various posts over the years; this is really confusing but in any case does not change anything since GOOGLE is always back as error.

Thanks for any help or pointers




function mail(to, subject, message)
  -- make sure these settings are correct

  local settings = {

    -- "from" field, only e-mail must be specified here

    from = '...',

    -- smtp username

    user = '...',

    -- smtp password

    password = '...',

    -- smtp server

    server = 'sss',

    -- smtp server port

    port = 465,

    secure = 'tlsv12',

    -- use STARTTLS mode

    --starttls = true,



  }



  local smtp = require('socket.smtp')



  if type(to) ~= 'table' then

    to = { to }

  end



  for index, email in ipairs(to) do

    to[ index ] = '<' .. tostring(email) .. '>'

  end



  -- message headers and body

  settings.source = smtp.message({

    headers = {

      to = table.concat(to, ', '),

      subject = subject,

      ['Content-type'] = 'text/html; charset=utf-8',

    },

    body = message

  })



  -- fixup from field

  settings.from = '<' .. tostring(settings.from) .. '>'

  settings.rcpt = to



  return smtp.send(settings)
end
Reply
#2
Hi,

Couple of things to check:

1) Make sure DNS and DG are set correct in the interface settings (otherwise you have no internet access)
2) Enable https://myaccount.google.com/lesssecureapps on your gmail account (otherwise mail from machines is blocked by google)
3) Use these settings in the common functions:
Code:
-- send an e-mail function mail(to, subject, message)   -- make sure these settings are correct   local settings = {     -- "from" field, only e-mail must be specified here     from = 'yourmail@gmail.com',     -- smtp username     user = 'yourmail@gmail.com',     -- smtp password     password = 'yoursecretpassword',     -- smtp server     server = 'smtp.gmail.com',     -- smtp server port     port = 465,     -- enable tls, required for gmail smtp     secure = 'tlsv1_2',   }   local smtp = require('socket.smtp')   if type(to) ~= 'table' then     to = { to }   end   for index, email in ipairs(to) do     to[ index ] = '<' .. tostring(email) .. '>'   end   -- fixup from field   local from = '<' .. tostring(settings.from) .. '>'   -- message headers and body   settings.source = smtp.message({     headers = {       to = table.concat(to, ', '),       subject = subject,       ['From'] = from,       ['Content-type'] = 'text/html; charset=utf-8',     },     body = message   })   settings.from = from   settings.rcpt = to   res, err = smtp.send(settings)   return res,err end
4) Send a mail
Code:
subject = 'E-mail test' message = 'Testing e-mail' res, err = mail('yourrecipient@gmail.com', subject, message)
Reply


Forum Jump: