``` kumo.on('smtp_server_message_received', function(msg) ---------- ReInjector code ---------------------------------- local is_reinjected = msg:get_first_named_header_value("is_reinjected") if is_reinjected ~= "yes" then print ("Received a new message to process") local client = kumo.http.build_client {} local msg_body = msg:get_data() -- update body here -- -- Tag this with a new header to prevent a loop msg:prepend_header("is_reinjected","yes") -- define and add tracking link to HTML part local my_tracking_link = 'Flowers in Chania' msg_body = msg_body:gsub("mailing", my_tracking_link .. " ") local msg_payload = kumo.json_encode { envelope_sender = msg:sender().email, content = msg_body, recipients = { { email = msg:recipient().email }, }, } print ("NEW PAYLOAD: " .. msg_payload) local request = client:post 'http://127.0.0.1:8000/api/inject/v1' request:header('Content-Type', 'application/json') request:body(msg_payload) -- local response = request:send() if response:status_is_success() then -- print ("successful reinjection, deleting original") -- That message replaces this one. Accept it, but drop it msg:set_meta('queue', 'null') return end local disposition = string.format( '%d %s %s', response:status_code(), response:status_reason(), response:text() ) -- Something went wrong. Assume temporary issue, but this logic -- should try harder to notice and report perm fails kumo.reject(400, disposition) end ------------------------------------------------------------------------ queue_helper:apply(msg) .... Continue with rest of existing event script... ``` Then also add the HTTP processor ``` kumo.on('http_message_generated', function(msg) print ("Processing HTTP injection") -- Call the queue helper to set up the queue for the message. queue_helper:apply(msg) local is_reinjected = msg:get_first_named_header_value("is_reinjected") if is_reinjected ~= "yes" then print("Processing the reinjected message") end -- SIGNING MUST COME LAST OR YOU COULD BREAK YOUR DKIM SIGNATURES dkim_signer(msg) end) ```