如何使用 lua 编程语言发送电子邮件?

how to send email using lua programming language?

有人可以详细解释如何使用 lua 发送电子邮件,并请分享模板。

用gmail账号发邮件也是一样的步骤吗?我在 windows 10 上使用 lua 5.1.

场景:我有一个 lua 函数,我需要从那里向少数用户发送邮件。任何帮助实施这将真正有帮助。 谢谢。

发件人:http://w3.impa.br/~diego/software/luasocket/smtp.html

smtp.send{
  from = string,
  rcpt = string or string-table,
  source = LTN12 source,
  [user = string,]
  [password = string,]
  [server = string,]
  [port = number,]
  [domain = string,]
  [step = LTN12 pump step,]
  [create = function]
}

这描述了函数 smpt.send,它接受一个 table 作为参数。 方括号中的字段是可选的。 阅读文档了解详情。

以下示例显示如何发送电子邮件。请注意 smtp.send 参数的 table 字段是如何填充值的。您必须为您的用例更改这些值。不知道有什么不清楚的地方。

如果您因为缺乏必要的 Lua 知识而无法理解它,我建议您学习初学者教程并阅读 Lua 参考手册和 Lua[ 中的编程] =15=]

-- load the smtp support
local smtp = require("socket.smtp")

-- Connects to server "localhost" and sends a message to users
-- "fulano@example.com",  "beltrano@example.com", 
-- and "sicrano@example.com".
-- Note that "fulano" is the primary recipient, "beltrano" receives a
-- carbon copy and neither of them knows that "sicrano" received a blind
-- carbon copy of the message.
from = "<luasocket@example.com>"

rcpt = {
  "<fulano@example.com>",
  "<beltrano@example.com>",
  "<sicrano@example.com>"
}

mesgt = {
  headers = {
    to = "Fulano da Silva <fulano@example.com>",
    cc = '"Beltrano F. Nunes" <beltrano@example.com>',
    subject = "My first message"
  },
  body = "I hope this works. If it does, I can send you another 1000 copies."
}

r, e = smtp.send{
  from = from,
  rcpt = rcpt, 
  source = smtp.message(mesgt)
}