簡體   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)我已經下載了所有庫,但我不知道為什么它不起作用。 這是我的代碼

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

第 80 行的代碼調用mime.b64() function,其中mimerequire "mime"調用的結果(其中 mime 模塊來自 luasocket 庫)。 除非 mime 模塊本身有問題(如果它來自正確的源並正確安裝,則不應該有),它很可能是由mime.lua文件在package.path中的某處可用引起的,所以它得到加載而不是實際的模塊。

如果您想進一步排除故障,只需在調試器中查看require "mime"的結果或使用package.searchpath("mime", package.path)來查看正在提取的內容(搜索路徑); 您可能還需要使用package.cpath進行嘗試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM