Enrich a message on the listener stage

Hello everyone,
I’m new to KumoMTA.

For testing purposes, I’ve installed KumoMTA and I’m currently running some tests

My next goal :slightly_smiling_face: : Basically, I would like to ensure that a message received on a specific Listener is enriched with a variable to be used later for certain routing operations.

I saw that this could be done within smtp_server_message_received using conn:get_meta('received_via'), but I would prefer to set this variable on the listener to keep everything organized.

There is a way to set a “context” key=value at listener session or is there anything I’m overlooking or a better way to achieve this?

Something like ( no way for the “customer” to add extra headers ) :

# dedicated listener for customer 123
kumo.start_esmtp_listener {
  listen = '10.0.0.1:25',
  context = {
     customer = '123'
  }
}
# dedicated listener for customer 456
kumo.start_esmtp_listener {
  listen = '10.0.0.2:25',
  context = {
     customer = '456'
  }
}

Apologies for the request, but I might be influenced by the current configuration/usage of my existing MTA.

there isn’t a way to statically declare it that way, but you could implement smtp_server_ehlo - KumoMTA Docs and then use a simple map to read the received_via and then assign your customer id meta value back to the connection metadata.

Hi Wez, thank you for the response.

So, something like that I think… I’ll try to see if I can get what I want :slightly_smiling_face:

kumo.on('smtp_server_ehlo', function(domain, conn_meta)
  -- Get the 'received_via' value
  local received_via = conn_meta:get_meta('received_via')

  -- Define a map (table) for 'received_via'
  local received_via_map = {
    ["10.0.0.1:25"] = "123",
    ["10.0.0.2:25"] = "456"
  }
  conn_meta:set_meta('customer', received_via_map[received_via])
end)

yeah, that’s what I was thinking

Hi Wez, my test works! I’ll leave for ( eventually ) reference.

kumo.on('smtp_server_ehlo', function(domain, conn_meta)
  -- Get the 'received_via' value
  local received_via = conn_meta:get_meta('received_via')

  -- Define a map (table) for 'received_via'
  local received_via_map = {
    ["10.0.0.1:25"] = "Tenant2",
    ["10.0.0.2:25"] = "Tenant3"
  }
  conn_meta:set_meta('customer', received_via_map[received_via])
end)

kumo.on('smtp_server_message_received', function(msg, conn_meta)
  msg:set_meta('tenant', conn_meta:get_meta('customer'))
end)

in /opt/kumomta/etc/queues.toml

...
[tenant.'Tenant2']
# Which pool should be used for this tenant
egress_pool = 'pool-2'

[tenant.'Tenant3']
# Which pool should be used for this tenant
egress_pool = 'pool-3'
...
$ swaks --to dummy-to-tenant2@example.com --from dummy-from@example.com --server 10.0.0.1 --port 25
$ swaks --to dummy-to-tenant3@example.com --from dummy-from@example.com --server 10.0.0.2 --port 25

$ sudo /opt/kumomta/sbin/tailer --tail /var/log/kumomta | jq '{recipient,egress_pool,egress_source}'
/var/log/kumomta/20241017-152217
waiting for more files
{
  "recipient": "dummy-to-tenant2@example.com",
  "egress_pool": "pool-2",
  "egress_source": "ip-2"
}
{
  "recipient": "dummy-to-tenant3@example.com",
  "egress_pool": "pool-3",
  "egress_source": "ip-3"
}

I don’t know if there are better ways to do it, but this exercise is gradually allowing me to better understand the potential of KumoMTA. Kudos to everyone!