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
|
## Event trigger: after message stored
|
||||||
|
|
||||||
|
Prints metadata of stored messages to STDOUT.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- Prints metadata of stored messages to STDOUT.
|
|
||||||
function inbucket.after.message_stored(msg)
|
function inbucket.after.message_stored(msg)
|
||||||
print("\n## message_stored ##")
|
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("date: %s", os.date("%c", msg.date)))
|
||||||
print(string.format("subject: %s", msg.subject))
|
print(string.format("subject: %s", msg.subject))
|
||||||
end
|
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