1package mtasts_test
2
3import (
4 "context"
5 "errors"
6 "log"
7 "log/slog"
8
9 "github.com/mjl-/mox/dns"
10 "github.com/mjl-/mox/mtasts"
11)
12
13func ExampleGet() {
14 ctx := context.Background()
15 resolver := dns.StrictResolver{}
16
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"})
20 if err != nil {
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")
24 }
25 // Continuing, we may have a record but not a policy.
26 } else {
27 log.Printf("domain implements mta-sts")
28 }
29 if record != nil {
30 log.Printf("mta-sts DNS record: %#v", record)
31 }
32 if policy != nil {
33 log.Printf("mta-sts policy: %#v", policy)
34 log.Printf("mta-sts policy text:\n%s", policyText)
35 }
36}
37