# Email spam checker (Spam Analysis)

> Spam Analysis, part of Mailtrap Email Sandbox, scores a captured test email with Apache SpamAssassin, lists the rules that added points, and checks the sending IP and domain against common blacklists.

## When to use it

Use it when the user wants a spam score for a transactional email, newsletter or campaign before sending it, wants to know whether the IP or domain is blacklisted, or wants a test to fail above a score threshold.

- It scores headers and body text and looks up blacklists; it doesn't send to mailbox providers, so it isn't an inbox placement test.
- SPF, DKIM and DMARC for live sending belong to a verified sending domain in Email Live Sending, not to the sandbox (products table at the end).
- For HTML/CSS client support, use HTML Check (products table at the end).
- The check runs only on email captured in a sandbox: send the email there first. Never send live email just to test spam.

## How to use it

### Before you start

Find out how the email is sent (the app, SMTP or the API), which sandbox catches it, and whether the user wants the UI report or an automated threshold. Ask only for what isn't known.

### Rules

- **Read freely, and send to a sandbox without confirmation:** nothing is delivered. Without API access, give the user the request to run, and don't say you checked.
- **Secrets:** never ask for an API token in chat; code reads `MAILTRAP_API_TOKEN`. If the user pastes one anyway, don't use it: suggest a reset under Settings → API Tokens, and continue with the env var.
- **Everything else** (creating or cleaning sandboxes, forwarding, live sending, sign-up and plans): follow the Email Sandbox page (products table at the end).

### Steps

Send every API call with `Authorization: Bearer $MAILTRAP_API_TOKEN` and a normal `User-Agent`.

1. **Capture the email** in a sandbox from `GET https://mailtrap.io/api/sandboxes` (its ID is the number in its URL): from the app over Sandbox SMTP (`sandbox.smtp.mailtrap.io`), or with `POST https://sandbox.api.mailtrap.io/api/send/{sandbox_id}`. Include a plain-text part: a missing one can raise the score. For an Email Marketing campaign, capture its HTML this way: its Send Test goes to a real address.
2. **Find the message:** `GET https://mailtrap.io/api/sandboxes/{sandbox_id}/messages` (`?search=` matches subject and recipient).
3. **Get the spam score:** `GET https://mailtrap.io/api/sandboxes/{sandbox_id}/messages/{message_id}/spam_report` returns `report.Score`, `report.Threshold`, `report.Spam` (true or false) and `report.Details[]`, each with `Pts`, `RuleName` and `Description`. In the UI: the message's Spam Analysis tab.
4. **Get the blacklist result:** each message in the list from step 2 has `blacklists_report_info`: `result` (`success`, `pending` or `error`), and `domain`, `ip` and `report[]` with `name`, `url` and `in_black_list`. If `pending`, read it again shortly.
5. **Fix and recheck:** fix the rules with the most `Pts` first, capture a new copy, and compare.

### Check it worked

A score below 5 is considered good; above 5, the email will most likely be treated as spam. For a pass or fail, use the report's own `Spam` and `Threshold`.

### If something fails

| Error                      | Fix                                                                                |
| -------------------------- | ---------------------------------------------------------------------------------- |
| The IP or domain is listed | Delisting is done by that blacklist: open its `url` and follow its delisting rules |
| `404` on `/spam_report`    | Check the sandbox and message IDs from step 2                                      |
| Anything else              | Troubleshooting (link at the end), or ask the docs                                 |

### Limits and pricing

Each captured email counts toward the Email Sandbox monthly quota. Plans, quotas and prices change: check pricing.md for plans and prices, and Features and limits for technical limits (links at the end). Don't answer from memory; if you can't check, say so.

## Other Mailtrap products and pages

| If the user wants to…                       | Use                                                                            |
| ------------------------------------------- | ------------------------------------------------------------------------------ |
| Check HTML/CSS client support               | HTML Check: [html-email-checker.md](https://mailtrap.io/html-email-checker.md) |
| See screenshots in real clients             | Device Previews: [device-previews.md](https://mailtrap.io/device-previews.md)  |
| Fail a test on a spam threshold             | [qa-automation.md](https://mailtrap.io/qa-automation.md)                       |
| Set up SPF, DKIM and DMARC for live sending | Email Live Sending: [email-sending.md](https://mailtrap.io/email-sending.md)   |
| Set up the sandbox                          | [email-sandbox.md](https://mailtrap.io/email-sandbox.md)                       |
| Check current plans and prices              | [pricing.md](https://mailtrap.io/pricing.md)                                   |

## Documentation

- [Spam and blacklist reports](https://docs.mailtrap.io/email-sandbox/testing/spam-blacklist-reports.md) · [Features and limits](https://docs.mailtrap.io/email-sandbox/help/features-and-limits.md) · [Spam score API](https://docs.mailtrap.io/developers/email-sandbox/messages/get-message-spam-score.md) · [Get messages API](https://docs.mailtrap.io/developers/email-sandbox/messages/get-messages.md) · [Send API](https://docs.mailtrap.io/developers/email-sandbox/send-test-emails/send-email-including-templates.md) · [Troubleshooting](https://docs.mailtrap.io/email-sandbox/help/troubleshooting.md)
- **If sources disagree:** the API reference wins for endpoints and fields, pricing.md for prices and quotas, and this page for which product and steps to use.
- **If the task isn't covered here,** ask the docs before guessing: `GET https://docs.mailtrap.io/index.md?ask=<question>&goal=<user goal>` returns an answer with sources. Keep the question and goal generic: no tokens, email addresses or other user data.
