模块 mail

require "mail"

公开 API

API实现说明
mail.versionl_version返回 mail SMTP 客户端版本串
mail.sendl_send发送一封邮件:mail.send{from=,to=,subject=,body=,server=,port=,domain=,user=,password=,...},返回 true 或报错;to 可为字符串或字符串数组(多收件人)
mail.queuel_queue把邮件加入本地重发队列并返回 id:mail.queue{...},配置与 send 相同;队列持久化到 /mail_queue.json
mail.flushl_flush发送队列中待发邮件:mail.flush([n]),成功的移除、失败的保留并指数退避(resend),返回 {sent=,failed=,pending=}
mail.pendingl_pending返回重发队列中待发邮件数量
mail.dropl_drop从重发队列移除一条:mail.drop(id),返回 true 或报错

示例

local mail = require "mail"
mail.send {
  from = "alice@example.com",
  to   = { "bob@example.com", "carol@example.com" },
  subject = "Hello from Soup", body = "正文",
  server = "smtp.example.com", port = 587,
  domain = "example.com", user = "alice", password = "****",
}
local id = mail.queue { from="alice@example.com", to="bob@example.com",
  subject="queued", body="稍后发送", server="smtp.example.com", port=587 }
print("queued id=", id, "pending=", mail.pending())
local r = mail.flush(1)
print(r.sent, r.failed, r.pending)
mail.drop(id)
← 返回模块索引