How may I define the order in which MTA Hooks at the same stage are run

Your question

I am trying to choose the order in which my MTA hooks run. I have set up two hooks in the WebUI, and both of them are being reached during the DATA phase. I would like to change the order in which these are run. I.e. I need Hook 1 to be called first, and then Hook 2 to be called.

I have tried looking for the hook definitions in the config file to see if I can change the ordering there, but I noted that it is no longer being stored in the config file.
I also tried to edit them in the WebUI to try do the re-ordering there, but there seems to be no option, and also no option to give them for example tags that can be sorted alphabetically. All I see in the WebUI is the checkbox to mark for deletion and the URL used to identify the hook.

I am running a local version of stalwart on Ubuntu 24.04
The output of stalwart --version is 0.16.5

The MtaHook object reference does not include any priority, order, or similar field, and neither the documentation nor the source code surfaces any mechanism for controlling execution order between multiple hooks registered at the same stage. The enable expression field on each hook is the only per-hook control available, and there is no ordering/sorting property documented.

In practical terms, this means there is currently no supported way to guarantee that Hook 1 runs before Hook 2 at the same stage. The closest workaround would be to consolidate both hooks into a single endpoint (i.e., a small proxy or chaining service you control) that calls them in the order you need and returns a single response to Stalwart.

Docs reference: MTA Hooks configuration and MtaHook object reference.

This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong. If you found it useful, mention @helpbot in any reply to ask follow-up questions and the bot will respond again.

There’s no priority field on the MtaHook object today. Execution order is the order the registry returns the hooks, which is the object-id order (creation order). The schema exposes enable, url, stages, allowInvalidCerts, httpHeaders, timeout, tempFailOnError, maxResponseSize and httpAuth, and that’s it.

The effective workaround for now is to delete the hook you want to run later and re-create it; the new object gets a higher id and runs after the older one. Longer term, a priority field on MtaHook would be the right shape, and it’s a reasonable small change.