Karta.Outbound.MXResolver (Karta v1.0.0)

Where to deliver mail for a domain (RFC 5321 §5.1): the addresses to try, in order.

  • The MX records of the domain, lowest preference first; hosts of equal preference in random order (§5.1, to spread the load).
  • No MX records (NODATA) means the implicit MX: the domain itself, with preference 0.
  • A null MX (0 ., RFC 7505) means the domain accepts no mail: a permanent failure. So is a domain that does not exist (NXDOMAIN).
  • Each host's addresses (A, AAAA) in the order the IP family policy gives; addresses Karta.NetGuard refuses are left out (private, loopback, carrier-grade NAT, unique local, NAT64, 6to4 and the other special ranges, unless the operator allows them): a recipient's domain must not make Karta connect into its own network.
  • An address literal ([192.0.2.1], [IPv6:2001:db8::1]) is the address itself.

Results:

  • {:ok, [target]} - at least one address to try; target is %{host: name, preference: n, address: ip, mx_secure: boolean, address_secure: boolean, canonical: name} (below).
  • {:error, :permanent, reason} - :invalid_domain, :no_such_domain, :null_mx or :no_address (MX hosts or an implicit MX without addresses, and every lookup answered).
  • {:error, :temporary, reason} - :dns (a lookup failed and nothing usable was found) or :blocked (every address was refused, e.g. an MX pointing at the loopback address or a private one).

DNSSEC, for DANE (RFC 7672 §2.2) and REQUIRETLS (RFC 8689 §4.2.1): a target's mx_secure is true when the answer that named its host was validated (Karta.DNS.Answer.secure): the MX records, or, for the implicit MX, the answer that the domain has none. address_secure is true when the address record it came from was validated (with every CNAME on the way), and canonical is the host's name after those CNAMEs. An address literal has neither.

Options:

  • :ip_family - :prefer_ipv4 (default), :prefer_ipv6, :ipv4_only or :ipv6_only. The other family's lookups are not made for the _only policies.
  • :blocked_networks, :allowed_networks - for Karta.NetGuard: the ranges refused instead of its default ones, and those allowed instead of the operator's.
  • :max_hosts - at most this many MX hosts are looked up (default 10).
  • :dns - options for Karta.DNS.lookup/3 (:resolver, :cache).
  • :shuffle - the function that orders hosts of equal preference (default Enum.shuffle/1).

Summary

Functions

Resolves domain (a domain or an address literal) to delivery targets.

Types

result()

@type result() ::
  {:ok, [target(), ...]}
  | {:error, :permanent,
     :invalid_domain | :no_such_domain | :null_mx | :no_address}
  | {:error, :temporary, :dns | :blocked}

target()

@type target() :: %{
  host: String.t(),
  preference: 0..65535,
  address: :inet.ip_address(),
  mx_secure: boolean(),
  address_secure: boolean(),
  canonical: String.t()
}

Functions

default_blocked_networks()

@spec default_blocked_networks() :: [Karta.CIDR.t()]

The ranges refused by default: Karta.NetGuard.default_blocked_networks/0.

resolve(domain, opts \\ [])

@spec resolve(String.t(), keyword()) :: result()

Resolves domain (a domain or an address literal) to delivery targets.