Our recommendation is to capture the headers into the message metadata to make the system run faster and more efficiently:
kumo.on('init', function()
kumo.configure_local_logs {
-- ..
meta = { 'subject', 'x_client_id' },
}
end)
kumo.on('smtp_server_message_received', function(msg, conn_meta)
-- Arrange to log the subject header in the most
-- efficient way, by capturing it into the message
-- metadata when we receive the message.
-- The `msg:import_x_headers` method will capture non-x-header
-- names when header names are explicitly passed like this:
msg:import_x_headers { 'subject', 'x-client-id' }
end)
But when i test , after msg:import_x_headers should add some code:
Thanks Mike.
Subject it is, but I also tested the X-Tenant and X-Campaign fields. When there is no msg:set_meta, it cannot be obtained. The detailed configuration is as follows:
kumo.on('smtp_server_message_received', function(msg)
-- Protect against SMTP Smuggling (https://sec-consult.com/blog/detail/smtp-smuggling-spoofing-e-mails-worldwide/)
local failed = msg:check_fix_conformance(
-- check for and reject messages with these issues:
'NON_CANONICAL_LINE_ENDINGS',
-- fix messages with these issues:
''
)
if failed then
kumo.reject(552, string.format('5.6.0 %s', failed))
end
msg:import_x_headers { 'from','Subject','X-Smtp-API','X-System', 'Message-Id' ,'X-Tenant','X-Campaign' }
-- Call the queue helper to set up the queue for the message.
msg:set_meta('from', msg:get_first_named_header_value 'from')
msg:set_meta('Subject', msg:get_first_named_header_value 'Subject')
msg:set_meta('Message-Id', msg:get_first_named_header_value 'Message-Id')
webhook(elk)
log_hooks:new {
name = 'elk',
batch_size = 500,
-- log_parameters are combined with the name and
-- passed through to kumo.configure_log_hook
log_parameters = {
-- metadata extracted from headers in smtp_server_message_received
meta = { 'from', 'Subject' ,'X-Smtp-API','X-System','Message-Id','X-Tenant','X-Campaign' },
per_record = {
Any = { enable = true },
},
},
constructor = function(domain, tenant, campaign)
-- send elk code
end,
}
After this config only from ,Subject,Message-Id can pass data to elk.
When you use the import function, variable names are normalized to lowercase and dashes become underscores. So X-My-Header will be saved as meta variable x_my_header.
If you test for meta X-My-Header it will be nil