MailAuth.SPF (MailAuth v0.1.0)

Copy Markdown View Source

SPF (RFC 7208): checks that the client IP may send mail for the MAIL FROM domain.

SPF needs the IP address of the client that connected, so it is for SMTP servers. Mail read later, such as over IMAP, has no trustworthy client IP: Received: headers are written by the sender and are not read.

The limits of RFC 7208 section 4.6.4 apply: at most 10 terms that cause DNS lookups, at most 2 that find nothing ("void lookups"), and at most 10 names from one mx or ptr. Going over is :permerror. The whole check is also under :deadline.

Options

  • :receiver: the name of the host doing the check, for the %{r} macro and for received_spf/2. Default "unknown"
  • :now: the time for the %{t} macro
  • :resolver, :deadline, :timeout: see MailAuth.Resolver and MailAuth

Summary

Functions

Checks SPF for a client IP, a MAIL FROM address and a HELO name.

Writes the Received-SPF: header for a result (RFC 7208 section 9.1), without a final line break.

Functions

check(ip, mail_from, helo, opts \\ [])

@spec check(
  :inet.ip_address() | String.t(),
  String.t() | nil,
  String.t() | nil,
  keyword()
) ::
  MailAuth.SPF.Result.t()

Checks SPF for a client IP, a MAIL FROM address and a HELO name.

ip is a tuple or a string. An empty mail_from (a bounce) checks the HELO name as postmaster@<helo>.

received_spf(r, opts \\ [])

@spec received_spf(MailAuth.SPF.Result.t(), keyword()) :: String.t()

Writes the Received-SPF: header for a result (RFC 7208 section 9.1), without a final line break.

Options: :receiver, the name of the host that did the check.