
If company emails land in spam or are rejected, the most common causes are an SPF record that exceeds the 10 DNS lookup limit (spf=permerror), more than one SPF record on the same domain, or DKIM never having been enabled for your custom domain in Microsoft 365. The fix is to merge all sources into a single SPF record, move bulk-sending services to subdomains, enable DKIM in the Defender portal, and start DMARC at p=none before tightening it step by step.
Symptoms: “spf=permerror”, “dmarc=fail” and “550 5.7.26”
- Company mail sent to Gmail addresses lands in Spam or bounces with “550 5.7.26 This email has been blocked because the sender is unauthenticated.”
- Gmail returns “5.7.27 This message was blocked because it didn’t pass SPF authentication.” or the temporary “4.7.26 This email has been rate limited because it is unauthenticated.”
- At recipients who use Microsoft 365, the Authentication-Results header of the message shows “spf=permerror”.
- The non-delivery report (NDR) contains “The message required too many lookups” or “The message exceeded the hop count”.
- The header shows “dkim=none” together with “dmarc=fail”, meaning the message was never DKIM-signed.
- The problem started after adding a newsletter tool, an ERP or e-invoice mailing module, or a website contact form, and it affects some recipients but not others.
Root cause: the 10-lookup limit, duplicate records and unaligned domains
SPF is defined in RFC 7208. According to section 4.6.4, the include, a, mx, ptr and exists mechanisms and the redirect modifier require DNS queries, and their total during evaluation must not exceed 10. If the limit is exceeded, the result is “permerror”. ip4, ip6 and all do not count. The real trap is nesting: a single include line can turn into several lookups once the includes inside the target record are added. Microsoft states explicitly that having fewer than 10 include statements does not guarantee fewer than 10 lookups. In addition, “void lookups” that return an empty answer should be limited to 2.
Receiving systems read the record from left to right and stop as soon as they match the sending IP. So mail sent through Microsoft 365 may pass while mail from a newsletter tool defined at the end of the record exceeds the limit and fails. That is why the issue appears to hit only some recipients.
The second common cause is more than one SPF record. Under RFC 7208 section 4.5, if a domain has more than one TXT record starting with v=spf1, the result is again permerror. Hosting panels and setup wizards of new services often add a new record instead of editing the existing one.
The third cause is DMARC alignment. SPF validates the envelope sender (MAIL FROM, 5321.MailFrom), which the recipient never sees; what the user sees is the From (5322.From) address. DMARC requires SPF or DKIM to both pass and align with the From domain. According to Microsoft Learn, Microsoft 365 does not DKIM-sign outbound mail from custom domains on its own; you have to enable it. If a newsletter tool also uses its own bounce domain, SPF returns “pass” but does not align, and DMARC fails.
Finally, Google and Yahoo tightened their rules from February 2024. All senders must use SPF or DKIM. Senders of more than 5,000 messages per day to Gmail must have both SPF and DKIM, a DMARC record of at least p=none, From alignment, one-click unsubscribe for marketing mail, and a spam rate below 0.3% in Postmaster Tools.
Step-by-step fix
- Read the current TXT records and count how many lines begin with v=spf1. If there is more than one, you have already found a problem.
- Query each include target separately to work out the total number of DNS lookups, including nested includes.
- Open the internet headers of a message that went to spam (you can paste them into Microsoft’s Message Header Analyzer) and compare the spf, dkim and dmarc results and the smtp.mailfrom, header.d and header.from domains in the Authentication-Results line.
- Merge all sources into a single SPF record. List your own servers that send from fixed IPs with ip4:. Microsoft explicitly recommends not flattening include:spf.protection.outlook.com into IP addresses, because those addresses change frequently.
- Move newsletter and bulk services to a subdomain such as news.yourcompany.com. Each subdomain has its own SPF record and its own 10-lookup budget. Configure the service either to DKIM-sign with your domain or to use your domain in MAIL FROM.
- Enable DKIM in Microsoft 365: on the DKIM tab at https://security.microsoft.com/authentication?viewid=DKIM, select the domain. If the status is “CnameMissing”, add the displayed selector1._domainkey and selector2._domainkey CNAME records to DNS, then turn on “Sign messages for this domain with DKIM signatures”.
- Roll out DMARC in stages: monitor first with p=none and rua reports, then p=quarantine (in pct=10, 25, 50, 75, 100 steps if needed), and finally p=reject. Microsoft recommends starting with low-volume subdomains and leaving the parent domain for last.
nslookup -type=TXT yourcompany.com
Resolve-DnsName -Name yourcompany.com -Type TXT
dig +short TXT yourcompany.com
nslookup -type=TXT spf.protection.outlook.com
nslookup -type=TXT _dmarc.yourcompany.comThe header of a problem message often looks like the following. Here SPF and DKIM pass on their own, but DMARC fails because neither aligns with the From domain:
Authentication-Results: spf=pass (sender IP is 198.51.100.10)
smtp.mailfrom=bounces.adatum.com; dkim=pass (signature was verified)
header.d=adatum.com; dmarc=fail action=oreject
header.from=contoso.com;compauth=fail reason=000Sample values for a merged SPF record, a subdomain and DMARC (including the command to read DKIM status in Exchange Online PowerShell):
yourcompany.com TXT v=spf1 ip4:203.0.113.25 include:spf.protection.outlook.com -all
news.yourcompany.com TXT v=spf1 include:<value-from-the-service> -all
_dmarc.yourcompany.com TXT v=DMARC1; p=none; rua=mailto:[email protected]
Get-DkimSigningConfig | Format-List Name,Enabled,Status,Selector1CNAME,Selector2CNAMECopy the existing SPF value somewhere before you change it. A wrong -all causes a forgotten sending source (for example, ERP e-invoice mail) to be rejected immediately. Do not move to p=reject in DMARC before you have read the reports; Microsoft also notes that outbound mail from domains with p=quarantine or p=reject that fails DMARC is routed through the high-risk delivery pool.
Lasting prevention
- Keep an inventory of every system that sends mail on behalf of the domain (Microsoft 365, ERP, e-invoicing, newsletter, web form, printer/scanner) and recalculate the lookup count before adding a new service.
- Use a TTL of at least 3600 seconds on SPF and DMARC TXT records.
- Send DMARC aggregate (rua) reports to a shared mailbox rather than a personal one and review them regularly.
- Add v=spf1 -all and v=DMARC1; p=reject; records to parked domains that never send mail.
- If you flattened a service into IP addresses, document it and compare it against the provider’s IP list at least every three months.
When should you call an expert?
When several sending systems, an on-premises server and multiple domains are in play at once, when DMARC reports show sources you do not recognise, or when critical mail such as e-invoices is being rejected, changing the record by trial and error can be risky. For issues like these that we encounter in the field at businesses in Denizli, Workas sorts out SPF, DKIM and DMARC as part of its Microsoft 365 service, starting with an inventory and moving in stages. We provide support Monday to Saturday, 08:00–18:00, and respond with priority in emergencies.
Frequently Asked Questions
I have fewer than 10 includes but still get permerror. Why?
What counts is the total number of DNS lookups, not include lines. The target of each include can contain further include, a or mx mechanisms, and all of them count toward the limit of 10.
Should I use ~all or -all?
Microsoft recommends -all together with DKIM and DMARC. DMARC treats both as SPF failures, but for ~all failures without a DKIM signature the DMARC policy is effectively ignored.
I enabled DKIM but Gmail still says spam. What should I check?
Check that header.d in the header aligns with your From domain, that your DMARC record is published, and for bulk mail that one-click unsubscribe is in place and the Postmaster Tools spam rate is below 0.3%.
Does moving to a subdomain change the address recipients see?
Yes, the From address becomes something like news.yourcompany.com. Microsoft explicitly recommends this because it separates your main domain’s reputation from bulk mail.
Sources
- RFC 7208: Sender Policy Framework (SPF), Bölüm 4.5 ve 4.6.4
- Microsoft Learn: Set up SPF to identify valid email sources for your Microsoft 365 domain
- Microsoft Learn: How to use DKIM for email in your custom domain
- Microsoft Learn: Set up DMARC to validate email in Microsoft 365
- Google Workspace: Email sender guidelines


