Trouble Setting "Message-ID" Header in Kumomta

Is there a way to set the “Message-ID” header using Kumomta? Currently, I am using the following code to add the “Message-ID” header, but it is not working:

msg:append_header(“Message-ID”, “samplemessageid”)

The email ends up in a bounced status with the error ‘This message is not RFC 5322 compliant. There are multiple Message-ID headers. To reduce the amount of spam sent to’.

Hey there @winsome-lion, thanks for posting. Please read the “Troubleshooting” and “How to Ask for Help” buttons below. If you would like a 1:1 support session from the KumoMTA team, details are at the “Book a Support Session” button below.

This is how I dealt with the exact same issue

kumo.on('smtp_server_message_received', function(msg, conn_meta)

    local messageIdHeader = msg:get_first_named_header_value('Message-ID')
    if messageIdHeader then
        if not string.match(messageIdHeader, "^<.+@" .. msg:from_header().domain .. ">$") then
            msg:remove_all_named_headers('Message-ID')
            msg:append_header('Message-ID', '<' .. msg:id() .. '@' .. msg:from_header().domain .. '>')
        end
    else
        msg:append_header('Message-Id', '<' .. msg:id() .. '@' .. msg:from_header().domain .. '>')
    end
end)

I make a check if message-id is already present and has the correct format, if not i remove it, then add a new correct one.
Here, you will find the methods you can use to operate over the message:
https://docs.kumomta.com/reference/message/
Hope it helps.

Why change the existing one?

In my case, the client was setting the message id, before reaching kumo, and I was also setting the message-id, so i had to add the check, since the client is sending a good message id, I leave it as is. I guess @winsome-lion is also adding a message id, ending up with 2 message id headers, therefore getting a reject.

Kumo adds a message ID if one is not present.

oh, this means I actually do not need the check , remove, and add

thanks @yearning-hyena, valuable information.

The check_fix_conformance function can do this for you automatically.

Thanks @faithful-ostrich , I will look into it. I think this method was not available, when I started the implementation.

but only if you use check_fix_conformance - KumoMTA Docs in fix mode

@yearning-hyena Currently i’m not setting any message id header, but when it reaches the gmail mail box, there is a default message id in it. i’m attaching the screenshot

Yeah but whatever injected the message in your laptop did set a message id.