Logging complete message data

I’m trying to get the complete message data (including body and attachments) out to another system in order to save it there for a period of time. Log Hooks don’t seem to be able to send out the complete data, so I tried routing the message via a HTTP request as explained here Routing Messages via HTTP Request - KumoMTA Docs :

kumo.on('make.message_saver', function(domain, tenant, campaign)
  local client = kumo.http.build_client {}
  local saver = {}

  function saver:send(message)
    -- Make the request
    local response = client
            :post('http://192.168.0.100:4242/message')
            :header('Content-Type', 'text/plain')
            :body(message:get_data())
            :send()

    -- and handle the result
    local disposition = string.format(
            '%d %s %s',
            response:status_code(),
            response:status_reason(),
            response:text()
    )
    if response:status_is_success() then
      -- Success!
      return disposition
    end

    -- Failed!
    kumo.reject(400, disposition)
  end
  return saver
end)

kumo.on('get_queue_config', function(domain, tenant, campaign, routing_domain)
  return kumo.make_queue_config {
    protocol = {
      custom_lua = {
        constructor = 'make.message_saver',
      },
    },
  }
end)

This works, but two things have changed compared to when I didn’t have this code in my config:

  1. I’m receiving an additional Log Message with Type Delivery which with its site parameter set to unspecified->example.com@lua:make.message_saver. Is it possible to prevent the log hook from sending these?
  2. I’m not receiving a bounce log message even though the Recipient email address domain doesn’t have a MX record (e.g. sending to someone@example.com). I assume this is because the message is actually being delivered to somewhere (via the message_saver function), which is also why I’m receiving the Delivery log message in (1). Is there a way to prevent this behavior?

your unconditional get_queue_config handler is re-routing all messages for all queues via HTTP to the endpoint you specified. With the config you shared, kumo will never try to use SMTP to deliver any messages, because all of the messages are being sent via HTTP.

You won’t see any Bounce records in the delivery logs because your HTTP delivery implementation always either succeeds or transiently fails (400).

What is the higher level goal for this other system? To save a copy of the incoming traffic? If so, I’d suggest that you make the HTTP call in the http_message_generated and/or smtp_server_message_received events, passing in a copy of the message from msg:get_data(). And if it fails, use kumo.reject to transiently fail the current message before it gets into kumo’s queues.

Yes it’s to save a copy of the incoming message.

Thanks @free-spirited-yorksh , I’ll try that!

Works like a charm, thanks again :slightly_smiling_face: