微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。