A spam filter is software in the email infrastructure that evaluates incoming messages and decides whether they are unwanted, then rejects, quarantines, tags or delivers them accordingly. It protects mailboxes from unsolicited bulk email, phishing and malware, and it operates at several points in the delivery chain, from the receiving mail transfer agent to the email client on a user device.
Modern spam filtering combines connection checks, sender authentication, content analysis and reputation data into a single verdict. Because senders constantly adapt, an effective filter is a layered system rather than one rule, and its quality is judged by two competing measures: how much spam it catches and how few legitimate messages it wrongly blocks.
How a spam filter evaluates a message
A spam filter evaluates a message in stages that follow the SMTP transaction. The first checks happen while the sending server is still connected, before the message body is even accepted. Rejecting at this point is efficient, because the receiving system avoids storing the message and the sender receives an immediate error instead of a later bounce message.
Once the message is accepted, the filter inspects headers, body and attachments. Most engines use a cumulative scoring model: each test adds or subtracts points, and the total is compared with configurable thresholds. A message just over the first threshold may be tagged or sent to a junk folder, while a very high score leads to quarantine or deletion. This avoids relying on any single signal, which spammers could easily evade.
The table below outlines the main filtering stages and what each one examines.
| Stage | When it runs | What it examines |
|---|---|---|
| Connection filtering | At TCP and SMTP greeting | Sending IP reputation, reverse DNS, rate |
| Envelope checks | During MAIL FROM and RCPT TO | Sender domain validity, recipient existence |
| Authentication checks | After headers arrive | SPF, DKIM, DMARC and ARC results |
| Content analysis | After full message is accepted | Text, links, attachments, formatting |
| Post-delivery actions | After the message reaches the mailbox | User reports, retroactive removal |
Detection techniques used by spam filters
Spam filters rely on a combination of detection techniques, each strong against some threats and weak against others. Reputation systems such as DNS-based blocklists score the sending IP address or domain, while statistical classifiers learn the word and token patterns that distinguish spam from legitimate mail. Larger providers add machine learning models trained on very large volumes of user feedback.
| Technique | How it works | Strength | Weakness |
|---|---|---|---|
| DNS blocklists | Query lists of known abusive IP addresses | Fast, cheap, early rejection | Collateral blocking of shared IPs |
| Bayesian filtering | Calculates spam probability from tokens | Adapts to each mailbox | Needs training, evaded by image spam |
| Heuristic rules | Match known spam patterns and traits | Transparent and tunable | Requires constant rule maintenance |
| URL reputation | Checks links against malicious domain lists | Catches phishing campaigns | New domains may not be listed yet |
| Greylisting | Temporarily defers mail from unknown senders | Stops simple spam bots | Delays legitimate first contact |
| Fingerprinting | Matches hashes of known bulk messages | Detects identical campaigns | Defeated by per-message variation |
Attachment and link handling has become central because phishing and malware cause more damage than nuisance advertising. Many gateways open attachments in a sandbox to observe behavior and rewrite links so they can be checked again at the moment of the click, catching sites that become malicious after delivery.
Spam filter and email authentication standards
A spam filter and email authentication solve different but connected problems. Authentication standards answer whether a message really comes from the domain it claims, while the spam filter decides whether the message is wanted. A fully authenticated message can still be spam, because spammers can authenticate their own domains.
| Standard | What it verifies | Effect on the spam filter |
|---|---|---|
| SPF | Sending IP is authorized for the envelope domain | Failure raises the score or triggers rejection |
| DKIM | Message signature matches the signing domain | Valid signature enables domain reputation tracking |
| DMARC | Visible From domain aligns with SPF or DKIM | Domain owner policy may require quarantine or reject |
| ARC | Authentication results survived forwarding | Allows trust in forwarded or list mail |
| BIMI | Verified brand logo for DMARC-protected domains | Indirect; requires strict DMARC enforcement |
The practical consequence is that authentication improves accuracy without replacing content analysis. A valid DKIM signature lets the filter attach reputation to a stable domain instead of a changing IP address, and strict DMARC policies make domain spoofing much easier to block, which removes one of the most common phishing tactics.
Deploying and tuning a spam filter
A spam filter can run at the gateway, on the mail server or in the email client, and many organizations combine all three. Gateway filtering, whether a cloud service placed in front of the MX records or an appliance, removes most junk before it reaches internal systems. Server-side filtering applies mailbox-specific rules, and client-side filtering adds personal preferences.
Tuning revolves around the balance between false positives and false negatives. A false positive is a legitimate message classified as spam, and it is usually more costly than a missed spam message, because an invoice or contract may go unseen. Administrators therefore start with conservative thresholds, monitor quarantine reports and adjust gradually.
| Situation | Recommended action | Reason |
|---|---|---|
| Partner mail lands in junk | Allow by authenticated domain, not by address | Address-only allowlists are easily spoofed |
| Spam volume rising | Lower the tag threshold slightly and review | Small steps limit new false positives |
| Phishing impersonates executives | Enable display name and lookalike checks | Targets spoofing that passes basic filters |
| Newsletters reported as spam | Route bulk mail to a separate folder | Users want it, but not in the inbox |
Limitations and common mistakes in spam filtering
No spam filter is perfect, because spam filtering is an adversarial problem. Senders test campaigns against popular filters, rotate domains and IP addresses, and use compromised legitimate accounts whose reputation is good. Highly targeted spear phishing may contain no suspicious links or attachments at all, which makes it very hard to detect by content.
- Broad allowlists that exempt entire domains, which attackers exploit by spoofing or compromising those domains.
- Silently deleting high-score mail instead of quarantining it, which hides false positives permanently.
- Ignoring outbound filtering, which leaves a compromised account free to damage the organization’s sending reputation.
- Relying on users to train personal filters without central monitoring of quarantine trends.
Put simply
A spam filter works like a careful receptionist for your email. Before each message reaches you, it checks who sent it, whether the sender is who they claim to be, and whether the content looks like junk or a scam. Suspicious messages go to a separate folder or are turned away.
The receptionist sometimes makes mistakes, so it is worth checking the junk folder occasionally. Still, without this filter, most inboxes would be flooded with advertising and fraud attempts.
In practice
A regional accounting firm with 80 employees receives about 12,000 inbound messages per day, of which roughly two thirds are rejected or quarantined. The firm routes its MX records through a cloud filtering gateway that performs blocklist checks, SPF, DKIM and DMARC validation, attachment sandboxing and link rewriting before forwarding clean mail to its hosted mailboxes.
During tax season, attackers send invoices that imitate a well-known client and contain a macro-enabled spreadsheet. The gateway notices that the sender domain fails DMARC alignment and that the attachment tries to download code in the sandbox. The messages are quarantined, and the IT administrator reviews the weekly report, releasing two legitimate messages flagged by mistake. The result is no infected workstations and only minor delays for genuine client mail.