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.

Attempt to index a nil value when sending email with lua
#1
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.
Reply


Messages In This Thread
Attempt to index a nil value when sending email with lua - by mattt - 17.07.2019, 12:49

Forum Jump: