mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-18 10:07:02 +00:00
Updated Lua Examples (markdown)
@@ -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 ##")
|
||||
|
||||
@@ -20,3 +21,24 @@ function inbucket.after.message_stored(msg)
|
||||
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
|
||||
```
|
||||
Reference in New Issue
Block a user