如何使用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
-- "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)
}

最新更新