模块 mail
require "mail"
公开 API
| API | 实现 | 说明 |
|---|---|---|
mail.version | l_version | 返回 mail SMTP 客户端版本串 |
mail.send | l_send | 发送一封邮件:mail.send{from=,to=,subject=,body=,server=,port=,domain=,user=,password=,...},返回 true 或报错;to 可为字符串或字符串数组(多收件人) |
mail.queue | l_queue | 把邮件加入本地重发队列并返回 id:mail.queue{...},配置与 send 相同;队列持久化到 |
mail.flush | l_flush | 发送队列中待发邮件:mail.flush([n]),成功的移除、失败的保留并指数退避(resend),返回 {sent=,failed=,pending=} |
mail.pending | l_pending | 返回重发队列中待发邮件数量 |
mail.drop | l_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)
← 返回模块索引