What I am trying to do is to send notifications using RSPAMD.
I Created a Lua script (notify_backend.lua)
to send a webhook when Rspamd detects a new email.
/opt/mailcow-dockerized/data/conf/rspamd/custom/notify_backend.lua
local rspamd_http = require "rspamd_http"
local rspamd_logger = require "rspamd_logger"
local ucl = require "ucl"
local function notify_backend(task)
-- Only process incoming mail
if task:get_user() == nil then
return
end
-- Get email details
local from = task:get_from()
local recipients = task:get_recipients()
local subject = task:get_header('Subject')
local message_id = task:get_header('Message-ID')
-- Skip if no valid recipient or Message-ID
if not recipients or not message_id then
return
end
-- For each recipient, send notification
for _, rcpt in ipairs(recipients) do
local rcpt_email = rcpt['addr']
-- Format data for API call
local request_data = {
recipient = rcpt_email,
from = from and from[1] and from[1]['addr'] or "unknown@example.com",
subject = subject or "(No subject)",
message_id = message_id
}
-- Convert to JSON
local json_data = ucl.to_format(request_data, 'json')
-- Send HTTP request to your Laravel backend
rspamd_http.request({
url = 'https://staging-api.hostpepper.com/api/imap-notify',
body = json_data,
headers = {
['Content-Type'] = 'application/json'
-- ['X-Api-Key'] = 'YOUR_SECRET_API_KEY'
},
callback = function(http_err, code, body, headers)
rspamd_logger.infox(task, 'Sent notification for %s: %s', rcpt_email, code)
end
})
end
end
-- Register the function to run on messages that passed spam checks
rspamd_config:register_symbol({
name = 'NOTIFY_BACKEND',
type = 'normal',
callback = notify_backend,
priority = 10
})
Enabled the script by/opt/mailcow-dockerized/data/conf/rspamd/local.d/custom_notifcations.conf
.include(try=true; priority=1) "${CONFDIR}/custom/notify_backend.lua"
My mounting on container is like this
volumes:
- ./data/hooks/rspamd:/hooks:Z
- ./data/conf/rspamd/custom/:/etc/rspamd/custom:z
- ./data/conf/rspamd/override.d/:/etc/rspamd/override.d:Z
- ./data/conf/rspamd/local.d/:/etc/rspamd/local.d:Z
- ./data/conf/rspamd/plugins.d/:/etc/rspamd/plugins.d:Z
- ./data/conf/rspamd/lua/:/etc/rspamd/lua/:ro,Z
- ./data/conf/rspamd/rspamd.conf.local:/etc/rspamd/rspamd.conf.local:Z
- ./data/conf/rspamd/rspamd.conf.override:/etc/rspamd/rspamd.conf.override:Z
- rspamd-vol-1:/var/lib/rspamd
Doing all this thing, still my script is not triggered whenever a new email is received. What should I do now