DEV Community

Lalit Kumar Jangid
Lalit Kumar Jangid

Posted on Fully Autonomous

Your email went to spam. The reason is written in the header.

When an email lands in spam, most people start guessing. Was it the subject line? The word "free"? Too many images? A link?

Sometimes it is one of those. But before you rewrite anything, there is a faster way to find out, and it does not involve guessing. Every email arrives with a header: a block of text, hidden by your mail app, that records who really sent it, which servers handled it and whether it passed the checks that mailbox providers run. The receiving server writes its verdict there in plain words.

You can read it in two minutes once you know which five lines matter.

How to open the header

The header is hidden by default, because it is long and most people never need it.

  • Gmail: open the email, click the three dots at the top right, then "Show original".
  • Outlook on the web: open the email, click the three dots, then View, then "View message details".
  • Apple Mail: open the email, then View, Message, "All Headers".

Send the email you are worried about to a personal Gmail account and open it there. Gmail's "Show original" page is the easiest to read, because it puts a summary table at the top with SPF, DKIM and DMARC and a pass or fail next to each.

The five lines that matter

A full header can run to sixty lines. You need five.

Enter fullscreen mode Exit fullscreen mode

From is the sender your reader sees. It is also the easiest field to fake, which is why the other four exist.

Return-Path is the address that receives bounce messages. Readers never see it. It is often on a different domain from the From address, and that difference is behind a large share of deliverability problems.

DKIM-Signature is a cryptographic signature added by the sending server. The part to look at is d=, the domain that signed the message.

Authentication-Results is the receiving server's verdict. This is the line to read first.

Received lines record the route. Each server that handled the message adds one at the top, so you read them from the bottom up.

Read the verdict first

Find Authentication-Results and look for three words.

spf=pass
dkim=pass
dmarc=pass
Enter fullscreen mode Exit fullscreen mode

If all three say pass, authentication is not your problem, and you can move on to content and reputation. If any of them says fail, none, neutral or softfail, you have found something concrete to fix, and it is very likely the reason for the spam folder.

Here is what each check means in plain terms.

SPF asks: is the server that sent this email allowed to send for the Return-Path domain? The answer comes from a DNS record on that domain listing the servers that may send for it.

DKIM asks: was this message signed by the domain it claims, and has it been changed since? The answer comes from checking the signature against a public key in DNS.

DMARC asks a stricter question than either: did SPF or DKIM pass for the same domain the reader sees in the From line?

That last question is where most confusion comes from.

The result that confuses everyone

You will sometimes see this:

spf=pass smtp.mailfrom=em.someprovider.net
dkim=pass header.i=@someprovider.net
dmarc=fail header.from=acme.com
Enter fullscreen mode Exit fullscreen mode

SPF passed. DKIM passed. DMARC failed. It looks like a mistake by Gmail. It is not.

Look at the domains. SPF passed for em.someprovider.net. DKIM passed for someprovider.net. The From address is on acme.com. Both checks passed, but they passed for your email provider's domain, not for yours.

DMARC requires at least one of them to pass for a domain that matches the From domain. This match is called alignment. Without it, the receiving server has proof that your provider sent the email and no proof that you did.

The fix is in your email provider's settings, not in your writing:

  • Set up custom DKIM, so the signature says d=acme.com.
  • Set up a custom Return-Path (often called a custom MAIL FROM domain), so SPF is checked against a subdomain of yours.

Either one gives you alignment. Do both, because forwarding often breaks SPF while a DKIM signature usually survives it.

Three domains, compared

It helps to write them side by side.

What Where to find it In a healthy email
From domain header.from acme.com
Return-Path domain smtp.mailfrom mail.acme.com
DKIM domain header.i or d= acme.com

If the second and third rows show your own domain or a subdomain of it, you are aligned. If they show your provider's name, you are borrowing their identity, and DMARC will fail the moment you publish a policy that enforces it.

What the other lines can tell you

Delays. Read the Received lines from the bottom up and compare the timestamps. If an email took forty minutes to arrive, one pair of lines will show a forty-minute gap, and the server named there is where it waited.

Who really sent it. The lowest Received lines show the first servers that handled the message. If you think an email came from your own system and those lines name a service you have never heard of, something else is sending as you.

Whether unsubscribing is easy. A marketing email should carry a List-Unsubscribe header. That header is what puts the "Unsubscribe" link next to the sender name in Gmail. If it is missing, readers who want out have one button left to press: "Report spam".

Reply handling. If there is a Reply-To header, replies go there and not to the From address. A reply-to on a different domain from the From address is another small thing some filters notice.

When everything passes and it still goes to spam

Authentication proves who you are. It does not prove that people want your email. If all three checks pass, the cause is one of these:

  • Reputation. A new domain, or a sudden jump in volume, has no history. Mailbox providers are cautious until they see how recipients react.
  • Complaints. If people mark your email as spam, later emails follow it there. Gmail has said it expects bulk senders to stay below a 0.3% complaint rate.
  • List quality. Sending to old or bought lists produces bounces and complaints, and both count against the domain.
  • Content. It matters less than people think, but a message that is one large image, or that hides its unsubscribe link, is easy to distrust.

These take longer to fix than a DNS record. But you should only start on them after the header says pass three times, because until then you are solving the wrong problem.

A two-minute routine

Next time an email misbehaves:

  1. Send it to a Gmail account and open "Show original".
  2. Read the SPF, DKIM and DMARC results. All three should say pass.
  3. Compare the From domain with the Return-Path domain and the DKIM d= domain. At least one should match yours.
  4. If something fails, fix it with your email provider: custom DKIM and a custom Return-Path.
  5. If everything passes, look at reputation, complaints and list quality, in that order.

The header will not tell you everything. It will tell you, in the receiving server's own words, whether the problem is who you are or what you sent, and that is the question to answer first.


We build Cresca, an email platform for marketing campaigns and transactional email. It signs your email with DKIM for your own domain and uses a custom MAIL FROM subdomain, so both checks align with your From address. Our glossary has a short reference for every field mentioned here: email header.

Top comments (0)