I recently had a problem with my mail server that manifested in me being unable to send emails when I was not at home, which didn’t make any sense, as my mail server, due to its not-being-in-my-home should actually have no clue whether I’m at home or not! Anyway, here’s what I did to find out what was going on.
(tl;dr: it was DNS. It’s always DNS. 😄) (Well, DNS-related, anyway.)
So, first thing was to check the log files of a client that sometimes can send mails and sometimes can not. Mail.app and its Connection Doctor offer a quite decent view, here. This is what the logfile says about an unsuccessful connection attempt:
INITIATING CONNECTION Nov 22 21:10:26.110 host:my.mail.server -- port:25 -- socket:0x0 -- thread:0x6000065f5e80
CONNECTED Nov 22 21:10:26.129 [kCFStreamSocketSecurityLevelNone] -- host:my.mail.server -- port:25 -- socket:0x600009ad4420 -- thread:0x6000065f5e80
READ Nov 22 21:10:26.148 [kCFStreamSocketSecurityLevelNone] -- host:my.mail.server -- port:25 -- socket:0x600009ad4420 -- thread:0x6000065f5e80
220 my.mail.server ESMTP Exim 4.86_2 Ubuntu Sun, 22 Nov 2026 21:10:26 +0100
WROTE Nov 22 21:10:26.148 [kCFStreamSocketSecurityLevelNone] -- host:my.mail.server -- port:25 -- socket:0x600009ad4420 -- thread:0x6000065f5e80
EHLO smtpclient.apple
READ Nov 22 21:10:26.167 [kCFStreamSocketSecurityLevelNone] -- host:my.mail.server -- port:25 -- socket:0x600009ad4420 -- thread:0x6000065f5e80
250-my.mail.server Hello smtpclient.apple [x.x.x.x]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-PRDR
250 HELP
If you are familiar with SMTP, you can probably spot the first problem immediately: STARTTLS is not being advertised on this connection; as it’s an unencrypted connection, it really should be advertised, though!
Next step: Exim’s configuration. I’m running Ubuntu, and they have split Exim’s configuration in many files. main/03_exim4-config_tlsoptions contains the following relevant lines:
.ifdef MAIN_TLS_ENABLE
# Defines what hosts to 'advertise' STARTTLS functionality to. The
# default, *, will advertise to all hosts that connect with EHLO.
.ifndef MAIN_TLS_ADVERTISE_HOSTS
MAIN_TLS_ADVERTISE_HOSTS = *
.endif
tls_advertise_hosts = !*.protection.outlook.com : MAIN_TLS_ADVERTISE_HOSTS
Okay, that looks rather standard, and to remind you, this does advertise STARTTLS when I’m connecting from home, so it cannot be completely broken! MAIL_TLS_ADVERTISE_HOSTS is not overridden anywhere else, so its default value of * (allowing advertising to every client) is being applied, and whenever I’m not at home, I should most definitely not have a hostname that ends with .protection.outlook.com. So why does this not apply?
The key to this behaviour can be found in Exim’s documentation, Chapter 10: “Domain, host, address, and local part lists”
If it encounters a permanent lookup failure in any item in the host list before it has found a match, Exim treats it as a failure and the default behavior is as if the host does not match the list.
While checking whether to advertise STARTTLS for an SMTP client, Exim tries to lookup it’s hostname, because the pattern configured by Ubuntu (!*.protection.outlook.com) requires a hostname. If a hostname cannot be found (because e.g. your mobile ISP has not configured reverse lookups correctly, or at all), which is a “permanent lookup failure,” it will abort checking the IP address, even though the next item in the list (*) should match everything. And blindingly obvious now, a failure here results in not advertising STARTTLS.
Luckily, pretty much the next sentence in the documentation contains information about how to change this behaviour to something slightly more reasonable. 😄
To change Exim’s behaviour, the special items
+include_unknownor+ignore_unknownmay appear in the list […]
So, my configuration has been changed as follows:
tls_advertise_hosts = +include_unknown : !*.protection.outlook.com : MAIN_TLS_ADVERTISE_HOSTS
And suddenly a connection attempt by Mail.app looks like this:
READ Nov 22 22:41:13.559 [kCFStreamSocketSecurityLevelNone] -- host:my.mail.server -- port:25 -- socket:0x600001ac6700 -- thread:0x600002405480
250-my.mail.server Hello smtpclient.apple [x.x.x.x]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-STARTTLS
250-PRDR
250 HELP
The only problem not solved by this: who the fuck would I send an email to in 2026?!
Leave a Reply