Build a DMARC record

Compose the TXT value for _dmarc.<domain> from a policy and an optional report address.

JavaScript Version 1.0.0 · MIT · by Oveyon · .md

build-a-dmarc-record.js
function dmarcRecord({ policy, rua }) { return ['v=DMARC1', `p=${policy}`, ...(rua ? [`rua=${rua}`] : [])].join('; '); }

Input & expected output

Input

{
  "policy": "none",
  "rua": "mailto:[email protected]"
}

Expected output

"v=DMARC1; p=none; rua=mailto:[email protected]"

The edge case

Input

{
  "policy": "reject"
}

Expected output

"v=DMARC1; p=reject"

Know the limits

  • Publish the value as a TXT record at _dmarc.<your-domain>; v=DMARC1 must come first (RFC 7489). Start with p=none and aggregate reports, then move to quarantine and reject once SPF or DKIM alignment holds.
  • Oveyon’s POST /v1/domains returns the SPF, DKIM and DMARC records to publish for a sending domain; prefer those values when they are available.

The function above is the implementation used by the lab. The lab validates JSON types and caps size before execution; include equivalent validation when accepting untrusted input in your application.

Source & maintenance

Written by Oveyon for this edition of 1loc.dev; it is not part of the original collection. Copyright (c) 2026 Oveyon. MIT licensed.

The function above is the implementation the lab runs and the tests exercise. Read the license.

Local fixture scope · Node.js 22.23.2 · reviewed October 28, 2026. No external service is required.

Keep exploring

Type two or more characters. Try “duplicate”, “webhook” or “retry”.