1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 17:47:03 +00:00

Updated Lua Examples (markdown)

James Hillyerd
2023-02-28 12:42:19 -08:00
parent 9b399b50f3
commit cf739cd919

@@ -2,8 +2,9 @@ By default Inbucket will load `inbucket.lua`, but you may use the `INBUCKET_LUA_
## Event trigger: after message stored
Prints metadata of stored messages to STDOUT.
```lua
-- Prints metadata of stored messages to STDOUT.
function inbucket.after.message_stored(msg)
print("\n## message_stored ##")
@@ -19,4 +20,25 @@ function inbucket.after.message_stored(msg)
print(string.format("date: %s", os.date("%c", msg.date)))
print(string.format("subject: %s", msg.subject))
end
```
Makes a JSON encoded POST to a web service.
```lua
local http = require("http")
local json = require("json")
BASE_URL = "https://myapi.example.com"
function inbucket.after.message_stored(msg)
local request = json.encode {
subject = string.format("Mail from %q", msg.from.address),
body = msg.subject
}
assert(http.post(BASE_URL .. "/notify/text", {
headers = { ["Content-Type"] = "application/json" },
body = request,
}))
end
```