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

问题描述

谁能详细解释一下如何使用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,它以单个表作为参数。 方括号中的字段是可选的。 阅读文档了解详情。

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

如果你因为缺乏必要的 Lua 知识而无法理解它,我建议你做一个初学者教程并阅读 Lua 参考手册和 Lua 编程

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

-- Connects to server "localhost" and sends a message to users
-- "[email protected]","[email protected]",-- and "[email protected]".
-- 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 = "<[email protected]>"

rcpt = {
  "<[email protected]>","<[email protected]>","<[email protected]>"
}

mesgt = {
  headers = {
    to = "Fulano da Silva <[email protected]>",cc = '"Beltrano F. Nunes" <[email protected]>',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)
}