So I tried sending an email using the luasocket smtp function with ssl but for some reason I get this error /usr/local/share/lua/5.1/socket/smtp.lua:80: attempt to call field 'b64' (a nil value) I have all the libraries downloaded and I don't know why it doesn't work.
This is my code
local smtp = require("socket.smtp")
local ssl = require('ssl')
local https = require 'ssl.https'
local mime = require("mime")
function sslCreate()
local sock = socket.tcp()
return setmetatable({
connect = function(_, host, port)
local r, e = sock:connect(host, port)
if not r then return r, e end
sock = ssl.wrap(sock, {mode='client', protocol='tlsv1'})
return sock:dohandshake()
end
}, {
__index = function(t,n)
return function(_, ...)
return sock[n](sock, ...)
end
end
})
end
local k, e = smtp.send{
from = "[REDACTED]",
rcpt = self.params.email,
user = "[REDACTED]",
password = "[REDACTED]",
port = 465,
server = "smtp.gmail.com",
source = smtp.message(message),
create = sslCreate
}
if not k then
print(e)
end
The code on line 80 calls
mime.b64()function, withmimebeing the result ofrequire "mime"call (where mime module comes from the luasocket library). Unless there is something wrong with the mime module itself (and if it came from the correct source and was properly installed, there shouldn't be), it's most likely caused bymime.luafile available somewhere inpackage.path, so it gets loaded instead of the actual module.If you want to troubleshoot it further, just review the result of
require "mime"in the debugger or usepackage.searchpath("mime", package.path)to see what is being picked up (searchpath); you may also need to try it withpackage.cpath.