简体   繁体   中英

smtp.lua:80: attempt to call field 'b64' (a nil value) when trying to send an email using lua socket

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, with mime being the result of require "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 by mime.lua file available somewhere in package.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 use package.searchpath("mime", package.path) to see what is being picked up ( searchpath ); you may also need to try it with package.cpath .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM