Prompt
My emails are going to spam and I don't know if it's my code or the provider. How do I debug this?
Latest observation
Debugging email deliverability is usually a process of isolating the cause, because spam placement can be affected by:
- your code
- your mail provider / sending IP
- DNS/authentication setup
- recipient reputation/history
- email content and formatting
Here’s a practical way to debug it.
1) Split the problem into “sending” vs “deliverability”
First confirm:
- Did the provider accept the message?
- Did the recipient mailbox receive it, and where did it land?
- Did it bounce, defer, or get silently filtered?
If you have SMTP logs or provider logs, look for:
250 OK/ accepted by provider- 4xx deferrals
- 5xx rejections
- complaint, bounce, or suppression events
If it’s accepted by the provider but lands in spam, it’s usually deliverability/reputation/authentication/content, not your SMTP code.
2) Check your authentication: SPF, DKIM, DMARC
These are the first things to verify.
SPF
- Ensure your sending domain has an SPF record authorizing the provider’s sending servers.
- Common issue: multiple SPF records. You should have only one SPF TXT record.
- Make sure the envelope-from / return-path aligns reasonably with the domain.
DKIM
- Make sure outgoing mail is being DKIM-signed.
- Verify the signature is valid and the selector/domain match what’s published in DNS.
- A broken DKIM signature is a very common reason for spam placement.
DMARC
- Check your DMARC policy and whether alignment passes.
- Start with monitoring (
p=none) if you’re unsure. - Review DMARC aggregate reports for authentication failures.
Quick test: send a message to a Gmail/Outlook test inbox and inspect the headers. Look for:
SPF=PASS/FAILDKIM=PASS/FAILDMARC=PASS/FAIL
3) Inspect the full message headers
In a received spam message, view the raw headers and check:
Authentication-ResultsReceivedchainMessage-IDFrom,Return-Path,Reply-ToList-Unsubscribe(for bulk mail)- any spam scoring headers like
X-Spam-Status
This can reveal:
- SPF/DKIM/DMARC failures
- mismatched domains
- missing unsubscribe headers
- suspicious relay behavior
4) Verify your sending IP/domain reputation
Even if the code is correct, reputation can be the issue.
Check:
- whether you’re on a shared IP pool with bad neighbors
- whether your IP/domain is listed on blocklists
- whether your domain is new or has low sending volume
- whether recipients are engaging or marking mail as spam
Useful checks:
- Google Postmaster Tools
- Microsoft SNDS / JMRP
- MXToolbox blacklist checks
- SenderScore-style reputation tools
5) Look at content and formatting
Spam filters can be triggered by the message body, HTML, or links.
Common issues:
- too many images, too little text
- URL shorteners
- suspicious attachments
- malformed HTML
- hidden text or styling tricks
- misleading subject lines
- excessive punctuation / spammy words
- mismatched visible link text vs actual URL
- tracking domains with bad reputation
Test with:
- plain text only
- minimal HTML
- no links
- no attachments
If that lands in inbox while the full version doesn’t, the issue is likely content-based.
6) Check recipient behavior and list quality
If you’re sending to a list:
- are addresses old or purchased?
- are you seeing hard bounces?
- are people opening/clicking?
- are there spam complaints?
Poor engagement can hurt reputation quickly.
7) Test from multiple inboxes/providers
Send the same email to:
- Gmail
- Outlook/Hotmail
- Yahoo
- a custom domain inbox
Compare where it lands and inspect headers. This helps determine whether the issue is:
- provider-specific
- domain-specific
- content-specific
8) Isolate your code
If you suspect the code:
- send the exact same content through your provider’s dashboard UI if possible
- compare headers from API-sent vs UI-sent messages
- check for accidental header bugs:
- malformed
From - broken MIME structure
- bad encoding
- incorrect line endings
- duplicate headers
- invalid charset
- missing MIME boundaries
- malformed
A bug in MIME formatting can absolutely hurt deliverability.
9) Use seed testing and inbox placement tools
For more systematic testing:
- send to seed addresses across major providers
- use tools like GlockApps, Mail-Tester, or Litmus-style email testing
- compare inbox vs spam placement and authentication results
10) Work through a simple diagnosis order
A good order is:
- Check provider logs
- Check SPF/DKIM/DMARC
- Inspect raw headers
- Test plain-text minimal email
- Check reputation/blocklists
- Review content and links
- Compare with provider-sent test email
- Test across Gmail/Outlook/Yahoo
Most common causes
In practice, the most common reasons emails go to spam are:
- missing or broken DKIM/SPF/DMARC
- bad sender reputation or shared IP issues
- low engagement / high complaints
- spammy content or bad HTML
- misconfigured return-path / From alignment
- provider-side throttling or suppression
If you want, I can help you debug it step by step. If you paste:
- your sending method/provider
- a redacted raw header from a spammed message
- your SPF/DKIM/DMARC records
…I can help identify the likely cause.