Using default connection strategy instead of one for each MTA node while ensuring correct EHLO

Your question

Hi there,

So we are running 10 MTA-only nodes, which sole job is to send out mail externally.
However we want to ensure that each MTA node sends out its own hostname (and not the defaultHostname) to make FCrDNS work as expected.

I have solved this by creating the following in /Settings/x:MtaOutboundStrategy:

Connection:
IF: system(‘node_hostname’) == ‘scp-mta01.loc.company.net’
THEN: ‘mta01’
IF: system(‘node_hostname’) == ‘scp-mta02.loc.company.net’
THEN: ‘mta02’
And so on all the way up to mta10…

And in /Settings/x:MtaConnectionStrategy i have created the connection strategies (mta01 to mta10) and set the EHLO hostname to be the correct hostname for that specific mta:
‘MTA01’ → EHLO Hostname → scp-mta01.loc.company.net–(not a link ty)
‘MTA02’ → EHLO Hostname → scp-mta02.loc.company.net–(not a link ty)
And so on all the way up to mta10…

This is immensely cumbersome to maintain in the long one, and i believe running through this many if statements must take its toll on the servers performance.

What we want to achieve is using the ‘default’ connection strategy and having stalwart to automatically parse the specific hostname of the MTA that is used to send the mail.
When not specifying a EHLO it unfortunately uses the defaultHostname, which fails the FCrDNS, since the defaultHostname points to our inbound Load Balancer for mx and client access.

How is this solved, without having to use individual connection strategies as we have done now?

Thanks!

I understand that topics in this category are triaged by a bot first but a human reply will follow up. If I’d prefer a human-only reply, I’ll add the no-ai tag to my topic.

on

The “one if per node” pattern can be collapsed to a single expression, since the strategy name itself can simply be the node’s hostname. You still need one MtaConnectionStrategy object per node (to hold each node’s distinct ehloHostname), but you no longer need any conditional logic in the connection expression itself.

Set /Settings/x:MtaOutboundStrategy → connection to just:

{"else": "system('node_hostname')"}

Then create one MtaConnectionStrategy object per node whose name is exactly the value returned by system('node_hostname') on that box (e.g. scp-mta01.loc.company.net), and set that object’s ehloHostname field to the same hostname. Since strategy lookup is a single name resolution (not a chain of evaluated conditions), this removes the 10-branch if/then tree entirely and is a constant-time lookup instead of sequentially evaluated conditions. There is currently no built-in mode that automatically derives the EHLO hostname from the node’s own hostname without an explicit ehloHostname value on the connection strategy; if the field is left empty, Stalwart falls back to the deployment’s defaultHostname, not the node’s OS hostname.

Reference: MTA Outbound Strategies, Connection Strategy, system() function.

This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong.

The Bots approach does simplify my existing logic, and the approach does work as explained. I have adapted that logic now to simplify.

However it still does not prevent me from maintaining a long list of connection strategies. I also cannot confirm if the bot is indeed correct about Stalwart not supporting this out of the box.

My question regarding how other people solve this is still valid.

Not out of the box. The EHLO name comes from the source IP’s ehloHostname, then the connection strategy’s, and otherwise the cluster-wide defaultHostname; the node’s own hostname never comes into it, and ehloHostname is a fixed value, not an expression. So each distinct EHLO name needs its own strategy object.

What you can avoid is the per-node logic. Name each strategy exactly after the node’s hostname and the connection expression becomes system('node_hostname') for every node, so adding an MTA means adding one strategy with a matching name. If a node has no matching strategy, delivery falls back to the default one and EHLOs as defaultHostname, with only a “connection strategy not found” event in the log, so watch for that when adding nodes. Performance isn’t a concern either way: ten string comparisons per delivery attempt are nothing next to the DNS lookups and TLS handshake.

Falling back to the node hostname when no EHLO name is set would make sense for setups like yours, and I’ll look into it.

Thanks for the speedy response.

Great news that we are not actively working against the logic as it was meant. The system('node_hostname') logic does indeed make this way more smooth, and it’s nice to know that performance is not a concern.

Glad to hear that you will look into it, as it seems like the only way to ensure FCrDNS out of the box in a clustering environment.

Kind regards,