Logic Machine Forum
Attempt to index a nil value when sending email with lua - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Attempt to index a nil value when sending email with lua (/showthread.php?tid=2160)



Attempt to index a nil value when sending email with lua - mattt - 17.07.2019

I'm trying to send an email in lua with slightly modified code from documentation:
Code:
function mail(to, subject, message)
  -- SMTP settings
  local settings = {
    from = 'mail@example.com',
    user = 'mail@example.com',
    password = 'password',
    server = 'smtp.office365.com',
    port = XYZ,
    secure = 'starttls',
  }

  local smtp = require('socket.smtp')

  -- message headers and body
  settings.source = smtp.message({
    headers = {
      to = escape(to),
      subject = subject,
      ['Content-type'] = 'text/html; charset=utf-8',
    },
    body = message
  })

  -- fixup from field
  settings.from = escape(settings.from)
  settings.rcpt = { escape(to) }

  return smtp.send(settings)
end

Even if I use the original documentation code I get an error:
Code:
Error in /usr/lib/lua/socket/tp.lua at line 0: attempt to index a nil value

I did not create tp.lua and unfortunately when I try to open it I get this:
Quote:The file is not displayed in the editor because it is either binary or uses an unspupported text encoding.



RE: Attempt to index a nil value when sending email with lua - Daniel - 17.07.2019

Does it have Keep source unselected?


RE: Attempt to index a nil value when sending email with lua - mattt - 17.07.2019

Are you asking if I have it in Scripting > User Libraries ? Like those:
[Image: FELDp4R.png]
No, I don't, these are all that are there and all of them have keep source checked.


RE: Attempt to index a nil value when sending email with lua - Daniel - 17.07.2019

OK, this is internal library. This is question to admin then.


RE: Attempt to index a nil value when sending email with lua - admin - 17.07.2019

Can you send access details via PM so I can check locally?