SPF flattening: what can go wrong, and how to do it safely

Flattening means replacing include: mechanisms with the ip4: and ip6: ranges they currently resolve to. IP mechanisms cost no DNS lookups, so a flattened record easily fits under the limit of 10.

The risks

Doing it safely

  1. Run node spf-check.mjs yourdomain.com --flatten with the free checker to get a preview, split automatically if it's long.
  2. Keep a copy of your original record.
  3. Re-check on a schedule (daily at least) and update the record when the resolved ranges change. Open-source flatteners such as cfspflat and sender_policy_flattener can do this on a cron job you run yourself.

No command line handy? Use the online SPF lookup checker: same checks, in the browser.