9 "github.com/mjl-/mox/dns"
10 "github.com/mjl-/mox/mtasts"
14 ctx := context.Background()
15 resolver := dns.StrictResolver{}
17 // Get for example.org does a DNS TXT lookup at _mta-sts.example.org.
18 // If the record exists, the policy is fetched from https://mta-sts.<domain>/.well-known/mta-sts.txt, and parsed.
19 record, policy, policyText, err := mtasts.Get(ctx, slog.Default(), resolver, dns.Domain{ASCII: "example.org"})
21 log.Printf("looking up mta-sts record and fetching policy: %v", err)
22 if !errors.Is(err, mtasts.ErrDNS) {
23 log.Printf("domain does not implement mta-sts")
25 // Continuing, we may have a record but not a policy.
27 log.Printf("domain implements mta-sts")
30 log.Printf("mta-sts DNS record: %#v", record)
33 log.Printf("mta-sts policy: %#v", policy)
34 log.Printf("mta-sts policy text:\n%s", policyText)