What Are SPF Macros?
SPF (Sender Policy Framework) macros are dynamic placeholders used inside SPF DNS TXT records. During SPF evaluation, these placeholders are automatically replaced with specific pieces of email metadata, such as the sender's IP address or domain name.
SPF macros make it possible to build flexible and scalable SPF records, especially for businesses with complex sending infrastructures. They're commonly used to reduce DNS lookups and help "flatten" long SPF records.
How SPF Macros Work
SPF macros begin with the % character. When an email is evaluated, the receiving mail server replaces each macro with real values from the SMTP session before checking authorization.
This substitution happens in real time during SPF validation.
Common SPF Macros
Some of the most commonly used SPF macros include:
-
%{s} — The full sender email address
-
%{i} — The sending IP address (IPv4 or IPv6)
-
%{o} — The sender's domain
-
%{h} — The HELO/EHLO domain used by the sending server
These macros allow SPF records to adapt dynamically based on how and where email is sent.
How SPF Macros Are Used
SPF macros are often used with the exists mechanism to perform dynamic authorization checks without relying on multiple include statements.
Example: v=spf1 exists:%{i}._spf.example.com -all
In this example:
-
%{i} is replaced with the sender's IP address.
-
The receiving server checks whether a DNS record exists for that IP under _spf.example.com.
-
If the record exists, SPF passes.
Why Use SPF Macros?
SPF macros provide several key benefits:
-
Reduce DNS lookups: Macros help avoid exceeding SPF's 10-DNS-lookup limit.
-
Simplify complex SPF records: They allow centralized management instead of long chains of include statements.
-
Scale with large infrastructures: Ideal for organizations with many sending IPs or dynamic email environments.
-
Enable SPF flattening: Macros support more maintainable and efficient SPF configurations.
SPF macros are a long-standing feature of the SPF standard (introduced in 2006) that enable dynamic, scalable email authentication. When used correctly, they simplify SPF management and help organizations stay within DNS lookup limits, but they should be implemented carefully. To that point, SPF macros can be difficult to troubleshoot and are best used by experienced administrators. Misuse can lead to unexpected SPF failures.
Use our free SPF Record Check to look up and validate any SPF record for a specific queried domain.