10 截屏后 然后把图片发送给邮箱 代码应该怎么写啊!

发布于 2020-05-23 14:55:02

截屏后 然后把图片发送给QQ邮箱或者其他邮箱 代码应该怎么写啊!!!

查看更多

关注者
1
被浏览
721
Evan
Evan 认证专家 2020-05-24
function main()
    local smtp = require("socket.smtp")
    local mime = require("mime")
    local ltn12 = require("ltn12")
    local f = "/var/touchelf/img.png"
    snapshotScreen(f)
    mesgt = smtp.message{
        headers = {
            to = "54321@qq.com", --收件人
            subject = "邮件标题"
        },
        body = {
            [1] = {
                body = mime.eol(0, "邮件正文")
            },
            [2] = {
                headers = {
                    ["content-type"] = 'text/plain; name="img.png"',
                    ["content-disposition"] = 'attachment; filename="img.png"',
                    ["content-description"] = 'the send script\'s source',
                    ["content-transfer-encoding"] = "BASE64"
                },
                body = ltn12.source.chain(
                    ltn12.source.file(io.open(f, "r")), 
                    ltn12.filter.chain(
                        mime.encode("base64"),
                        mime.wrap()
                    )
                )
            },
        }
    }
    r,e = smtp.send{
        server = "smtp.qq.com",     --邮箱服务器
        user = "12345@qq.com",     --用户名
        password = "password",     --密码或授权码
        from = "<12345@qq.com>",   --发件人
        rcpt = {                    --发送列表
            "<12345@qq.com>"
        },
        source = mesgt              --发送内容
    }
    if r then 
        logDebug("ok")
    else
        logDebug(e)
    end
end

如果一次发送多个图片拷贝body下的[2]内容,添加[3],[4]即可.望采纳

1 个回答

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览