【问题标题】:smtp.lua:80: attempt to call field 'b64' (a nil value) when trying to send an email using lua socketsmtp.lua:80:尝试使用 lua 套接字发送电子邮件时尝试调用字段“b64”(一个 nil 值)
【发布时间】:2021-08-26 16:35:13
【问题描述】:

所以我尝试使用带有 ssl 的 luasocket smtp 函数发送电子邮件,但由于某种原因,我收到此错误 /usr/local/share/lua/5.1/socket/smtp.lua:80: attempt to call field 'b64' (a nil value) 我已经下载了所有库,但我不知道为什么它不起作用。 这是我的代码

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

【问题讨论】:

    标签: email lua smtp luasocket luasec


    【解决方案1】:

    第 80 行的代码调用 mime.b64() 函数,mimerequire "mime" 调用的结果(其中 mime 模块来自 luasocket 库)。除非 mime 模块本身有问题(如果它来自正确的源并正确安装,则不应该有),它很可能是由 mime.lua 文件在 package.path 的某处可用引起的,所以它得到加载而不是实际的模块。

    如果您想进一步排除故障,只需在调试器中查看require "mime" 的结果或使用package.searchpath("mime", package.path) 来查看正在提取的内容(searchpath);您可能还需要使用package.cpath 进行尝试。

    【讨论】:

      猜你喜欢
      • 2018-05-30
      • 2016-03-05
      • 1970-01-01
      • 2023-03-16
      • 2017-04-03
      • 2019-09-15
      • 1970-01-01
      • 2014-03-13
      • 2011-07-30
      相关资源
      最近更新 更多