I would like to differentiate emails into tenants. Can I set the tenant based on the sender address or maybe based on the injected port on kumomta?
I see that tenant can be set using a header, but I would think that once injected in KumoMTA I would be able to set a tenant based on the sender domain?
I tried to by default change the tenant of any mail in the init.lua with
kumo.on('smtp_server_message_received', function(msg)
-- Accept and discard all messages
msg:set_meta('tenant', 'mytenant')
end)
but I don’t see the tenant in the logs json… Am I missing something here?
Okay… After asking the question I figured that maybe I need to set the log to show the meta field. So yeah when configureing the locl log to do so.. I can see the tenant to be ‘mytenant’ .
kumo.configure_local_logs {
log_dir = '/var/log/kumomta',
-- Flush logs every 10 seconds.
-- You may wish to set a larger value in your production
-- configuration; this lower value makes it quicker to see
-- logs while you are first getting set up.
max_segment_duration = '10s',
meta = { 'tenant' },
}
Alright, I might answer my own question. While tracing I noted that received_via is also a meta data… so you need to fetch that data first before you can filter on it. My example now works.
kumo.on('smtp_server_message_received', function(msg)
local my_received_via = msg:get_meta('received_via')
-- Accept and discard all messages
if my_received_via == "127.0.0.1:26" then
msg:set_meta('tenant', 'port26')
else
msg:set_meta('tenant', 'mydefault')
end
end)
And with the tenant info you can specify tenant specific egress pools, I guess even with the policy-extras.queue.