Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Email delivery

Mail from your own domain keeps landing in the spam folder

ErrorMessages from our own domain arrive in Gmail's spam folder

Short answer

Open a message that went to spam and read its Authentication-Results header: it shows whether SPF, DKIM and DMARC passed, and for which domain. Since February 2024 Gmail and Yahoo expect SPF or DKIM from every sender, aligned DMARC from bulk senders, and valid reverse DNS for the sending IP. Fix the first check that failed before you touch the content.

  • Applies to dig (BIND 9.18), Postfix 3.8, OpenDKIM 2.11, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Open a message that landed in spam and view its source (in Gmail: More, then Show original). Save it as message.eml and pull out the authentication lines. The first result that is not pass is the one to fix.

    grep -iE '^(Authentication-Results|ARC-Authentication-Results|Received-SPF|DKIM-Signature):' -A3 message.eml
  2. 2Match what you see, then jump to its fix

    1. 1spf=fail, spf=softfail or spf=permerror in Authentication-ResultsSPF fails, or the record itself is brokenFix
    2. 2dkim=none, dkim=fail or dkim=neutral, or no DKIM-Signature header at allMessages are not DKIM-signed, or the published key does not matchFix
    3. 3spf=pass and dkim=pass, yet dmarc=fail; smtp.mailfrom or header.d shows your provider's domain instead of yoursSPF and DKIM pass, but for someone else's domainFix
    4. 4Gmail bounces with code 5.7.25, or the sending IP's PTR is a generic name from the hosting companyYour own mail server has no matching reverse DNSFix
    5. 5spf, dkim and dmarc all pass, and newsletters still go to spam, mostly at Gmail and YahooAuthentication passes, but bulk mail breaks the volume rulesFix

What does the error look like?

  • Messages from our own domain arrive in Gmail's spam folder
  • dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=example.com
  • 550-5.7.26 Unauthenticated email from example.com is not accepted due to domain's DMARC policy
  • spf=permerror

Cause 1 of 5

SPF fails, or the record itself is broken

1Check

SPF is checked against the envelope sender (the Return-Path), not the From line. A domain may publish only one SPF record, and checking it may cost at most 10 DNS lookups; breaking either rule gives permerror, which receivers treat as a failure. Every include, a and mx term costs a lookup, and so do the terms inside each include.

dig +short TXT example.com | grep spf1

2Fix

Keep a single record that names every system sending as you: your own server, the app's mail provider, the helpdesk, the newsletter tool. Drop services you no longer use and end with ~all or -all.

example.com.  3600  IN  TXT  "v=spf1 ip4:203.0.113.10 include:_spf.google.com include:sendgrid.net ~all"

3Verify

Exactly one SPF record comes back, and a fresh test message shows spf=pass with your domain in smtp.mailfrom.

dig +short TXT example.com | grep -c spf1   # must print 1
Did this fix it?

Cause 2 of 5

Messages are not DKIM-signed, or the published key does not match

1Check

Take the selector from the s= tag of the DKIM-Signature header and fetch the public key published under it. A missing record, a key broken while pasting a long TXT value, or a key rotated on the server but not in DNS all fail. Gmail requires keys of at least 1024 bits and recommends 2048.

dig +short TXT mail._domainkey.example.com
sudo opendkim-testkey -d example.com -s mail -vvv

2Fix

Turn on DKIM for your domain at every sending service (each one gives you DNS records to publish). For your own Postfix server, generate a key with OpenDKIM, point its Domain, Selector and KeyFile settings (or KeyTable and SigningTable) at the key, publish the TXT file it writes, and restart the signer.

sudo mkdir -p /etc/opendkim/keys/example.com
sudo opendkim-genkey -b 2048 -d example.com -s mail -D /etc/opendkim/keys/example.com/
sudo cat /etc/opendkim/keys/example.com/mail.txt   # publish as mail._domainkey.example.com
sudo chown -R opendkim:opendkim /etc/opendkim/keys
sudo systemctl restart opendkim

3Verify

The signer logs a signature on outgoing mail, and the next test message shows dkim=pass header.i=@example.com.

sudo grep "DKIM-Signature field added" /var/log/mail.log | tail -n 3
Did this fix it?

Cause 3 of 5

SPF and DKIM pass, but for someone else's domain

1Check

DMARC only passes when SPF or DKIM passes for a domain that matches the From line (in relaxed mode, the same registered domain). A provider left on its defaults often signs with its own domain and takes bounces at its own address, so both checks pass for the provider and DMARC still fails for you.

grep -oiE '(smtp.mailfrom|header.d|header.i|header.from)=[^ ;]+' message.eml | sort -u

2Fix

In each provider's dashboard, set up domain authentication: a DKIM key under your domain and a custom bounce subdomain such as bounce.example.com. Then publish a DMARC record, starting at p=none with a rua address so the reports show which sources still fail.

_dmarc.example.com.  3600  IN  TXT  "v=DMARC1; p=none; rua=mailto:dmarc@example.com"

3Verify

The record is published, and new messages show dmarc=pass with header.from=example.com.

dig +short TXT _dmarc.example.com
Did this fix it?

Cause 4 of 5

Your own mail server has no matching reverse DNS

1Check

Look up the PTR record of the server's public IP, then look that name up forwards. Gmail and Yahoo want valid records in both directions, and the name should be the one the server gives in HELO.

dig +short -x 203.0.113.10
dig +short A mail.example.com
postconf myhostname

2Fix

Set the PTR in your hosting provider's panel (whoever owns the IP controls it, not your DNS host), give that name an A record pointing back at the IP, and make Postfix introduce itself with the same name.

sudo postconf -e 'myhostname = mail.example.com'
sudo systemctl reload postfix

3Verify

The forward lookup of the PTR name returns the same IP.

[ "$(dig +short A "$(dig +short -x 203.0.113.10)")" = "203.0.113.10" ] && echo forward-confirmed
Did this fix it?

Cause 5 of 5

Authentication passes, but bulk mail breaks the volume rules

1Check

Senders of 5,000 or more messages a day to Gmail must also offer one-click unsubscribe on marketing mail, and every sender must keep the reported spam rate under 0.3%; Yahoo sets the same two rules. Google's Postmaster Tools shows your spam rate and reputation. Google says it began ramping up enforcement, including rejections, in November 2025.

grep -iE '^List-Unsubscribe(-Post)?:' message.eml

2Fix

Add both RFC 8058 headers to marketing mail, process unsubscribes within two days (Yahoo's rule), and stop mailing addresses that bounce or never open.

List-Unsubscribe: <https://example.com/unsubscribe?u=abc123>, <mailto:unsubscribe@example.com?subject=unsubscribe>
List-Unsubscribe-Post: List-Unsubscribe=One-Click

3Verify

New messages carry the one-click header, and Postmaster Tools shows the spam rate falling over the following weeks.

grep -i '^List-Unsubscribe-Post: List-Unsubscribe=One-Click' message.eml
Did this fix it?

How do I stop it coming back?

  • Before switching on any new sending service, add it to SPF, set up its DKIM under your domain and recount the SPF lookups.
  • Read DMARC aggregate reports every week, and move from p=none to quarantine only when every real source passes.
  • Send newsletters from a subdomain such as news.example.com, so their reputation stays apart from invoices and password resets.
  • Watch Google Postmaster Tools for spam rate and reputation, not just your bounce count.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Email

Outlook.com bounces your mail with 550 5.7.515

status=bounced (host hotmail-com.olc.protection.outlook.com[...] said: 550 5.7.515 Access denied

550 5.7.515 means Outlook.com counts your From domain as a high-volume sender (5,000 or more messages a day to Microsoft consumer addresses) and the message failed its authentication rules.

4 causes, each with a fix

Email

Postfix refuses to send with "Relay access denied"

454 4.7.1 <user@example.net>: Relay access denied

Postfix says Relay access denied when a client asks it to deliver to a domain it does not host, and the client is neither listed in mynetworks nor logged in with SASL.

5 causes, each with a fix

Email

PHP mail() returns true but the email never arrives

Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing

mail() returning true only means the message was accepted for delivery, not that it arrived.

4 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.