简体   繁体   English

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

[英]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. 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)我已经下载了所有库,但我不知道为什么它不起作用。 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).第 80 行的代码调用mime.b64() function,其中mimerequire "mime"调用的结果(其中 mime 模块来自 luasocket 库)。 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.除非 mime 模块本身有问题(如果它来自正确的源并正确安装,则不应该有),它很可能是由mime.lua文件在package.path中的某处可用引起的,所以它得到加载而不是实际的模块。

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 );如果您想进一步排除故障,只需在调试器中查看require "mime"的结果或使用package.searchpath("mime", package.path)来查看正在提取的内容(搜索路径); you may also need to try it with package.cpath .您可能还需要使用package.cpath进行尝试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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