diff --git a/Lua-Examples.md b/Lua-Examples.md index ad30907..6aabb33 100644 --- a/Lua-Examples.md +++ b/Lua-Examples.md @@ -1,5 +1,31 @@ +**Warning**: Lua support in Inbucket is still in a preview state, please expect the API and features to evolve before a full release. + By default Inbucket will load `inbucket.lua`, but you may use the `INBUCKET_LUA_PATH` environment variable to change that. +## Event trigger: before mail accepted + +This event fires when Inbucket is evaluating an SMTP "MAIL FROM" command. + +Denies mail that does is not from james*@example.com: + +```lua +function inbucket.before.mail_accepted(from_localpart, from_domain) + print(string.format("\n### inspecting from %s@%s", from_localpart, from_domain)) + + if from_domain ~= "example.com" then + -- Only allow example.com mail + return false + end + + if string.find(from_localpart, "james") ~= 1 then + -- Only allow mailboxes starting with 'james' + return false + end + + return true +end +``` + ## Event trigger: after message stored Prints metadata of stored messages to STDOUT: