quickstart: check if domain was registered recently, and warn about potential deliverability issues

we use 6 weeks as the cutoff, but this is fuzzy, and will vary by mail
server/service provider.

we check the domain age using RDAP, the replacement for whois. it is a
relatively simple protocol, with HTTP/JSON requests. we fetch the
"registration"-related events to look for a date of registration.
RDAP is not available for all country-level TLDs, but is for most (all?) ICANN
global top level domains. some random cctlds i noticed without rdap: .sh, .au,
.io.

the rdap implementation is very basic, only parsing the fields we need. we
don't yet cache the dns registry bootstrap file from iana. we should once we
use this functionality from the web interface, with more calls.
This commit is contained in:
Mechiel Lukkien
2025-02-07 11:16:30 +01:00
parent c7354cc22b
commit 2f0997682b
5 changed files with 322 additions and 3 deletions

View File

@ -35,6 +35,8 @@ import (
"github.com/mjl-/mox/dnsbl"
"github.com/mjl-/mox/mlog"
"github.com/mjl-/mox/mox-"
"github.com/mjl-/mox/publicsuffix"
"github.com/mjl-/mox/rdap"
"github.com/mjl-/mox/smtp"
"github.com/mjl-/mox/store"
)
@ -102,7 +104,7 @@ output of "mox config describe-domains" and see the output of
var skipDial bool
c.flag.BoolVar(&existingWebserver, "existing-webserver", false, "use if a webserver is already running, so mox won't listen on port 80 and 443; you'll have to provide tls certificates/keys, and configure the existing webserver as reverse proxy, forwarding requests to mox.")
c.flag.StringVar(&hostname, "hostname", "", "hostname mox will run on, by default the hostname of the machine quickstart runs on; if specified, the IPs for the hostname are configured for the public listener")
c.flag.BoolVar(&skipDial, "skipdial", false, "skip check for outgoing smtp (port 25) connectivity")
c.flag.BoolVar(&skipDial, "skipdial", false, "skip check for outgoing smtp (port 25) connectivity or for domain age with rdap")
args := c.Parse()
if len(args) != 1 && len(args) != 2 {
c.Usage()
@ -582,8 +584,8 @@ messages over SMTP.
}
}
// Check outgoing SMTP connectivity.
if !skipDial {
// Check outgoing SMTP connectivity.
fmt.Printf("Checking if outgoing smtp connections can be made by connecting to gmail.com mx on port 25...")
mxctx, mxcancel := context.WithTimeout(context.Background(), 5*time.Second)
mx, _, err := resolver.LookupMX(mxctx, "gmail.com.")
@ -619,6 +621,41 @@ in mox.conf and use it in "Routes" in domains.conf. See
`)
}
// Check if domain is recently registered.
rdapctx, rdapcancel := context.WithTimeout(context.Background(), 10*time.Second)
defer rdapcancel()
orgdom := publicsuffix.Lookup(rdapctx, c.log.Logger, domain)
fmt.Printf("\nChecking if domain %s was registered recently...", orgdom)
registration, err := rdap.LookupLastDomainRegistration(rdapctx, orgdom)
rdapcancel()
if err != nil {
fmt.Printf(" error: %s (continuing)\n\n", err)
} else {
age := time.Since(registration)
const day = 24 * time.Hour
const year = 365 * day
years := age / year
days := (age - years*year) / day
var s string
if years == 1 {
s = "1 year, "
} else if years > 0 {
s = fmt.Sprintf("%d years, ", years)
}
if days == 1 {
s += "1 day"
} else {
s += fmt.Sprintf("%d days", days)
}
fmt.Printf(" %s", s)
// 6 weeks is a guess, mail servers/service providers will have different policies.
if age < 6*7*day {
fmt.Printf(" (recent!)\nWARNING: Mail servers may treat messages coming from recently registered domains\n(in the order of weeks to months) with suspicion, with higher probability of\nmessages being classified as junk.\n\n")
} else {
fmt.Printf(" OK\n\n")
}
}
}
zones := []dns.Domain{