Build a DMARC record
Compose the TXT value for _dmarc.<domain> from a policy and an optional report address.
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.
Keep exploring
- Convert an email domain to punycode — Keep the local part and convert an international domain to its ASCII xn-- form.
- Get the domain of an email address — Take the part after the last @ and lowercase it, for domain checks and grouping.
- Mask an email address for logs — Keep the first character and the domain; hide the rest of the local part.