The anti-spam stack end to end: score, greylisting, SPF, DKIM, DMARC, DNSBL, SURBL
-
Written for 6.3.4. hMailServer 6.3.7 (17 October 2026) reads a DNS lookup that fails as a failure, not as a name with no addresses: the HELO and PTR tests no longer score a name they could not look up, a DNS blacklist and SURBL no longer read a failed lookup as "not listed", and a DKIM selector that is a CNAME whose query failed is
TempFail, notPermFail. SURBL reads a link's host that is not ASCII by UTS 46 and an HTML part's character references as a browser does, and SpamAssassin is sent a collected message's ownReturn-Path, so its SPF and envelope rules may score such mail differently. The DMARC check's pass now also decides whether a forward of mail from outside whoseFromnames a hosted domain's organisation is given an envelope sender in that organisation, and no pass is recorded for a message the check did not judge: DMARC off, a sender on the white list or an IP range with spam protection off, a message overAntiSpam.MaximumMessageSize, or one the tests before it had already scored to the higher threshold. In the Control Panel the sidebar has a Spam filtering group, with its six allow and block lists under Lists, and a Virus scanning group, and Ctrl+K takes every old title to its page. See the 6.3.7 announcement. hMailServer 6.3.8 (2 November 2026) lets Rspamd learn from the Junk folder beside SpamAssassin: a message a user moves into Junk is taught as spam, and one moved out as ham, to the filterMoveLearningBackendnames, SpamAssassin by default and taught as before, and nothing is sent to Rspamd until it is chosen and its controller and classifier are set (JunkFolderLearning.md). See the 6.3.8 announcement.This topic walks through every layer hMailServer 6.3.4 puts between an SMTP session and a mailbox: the two thresholds, the twelve tests in the order they run, greylisting and its 6.3.4 hardening, the DNS and URL blocklists, SPF, DKIM, DMARC and ARC, SpamAssassin, and the quarantine. The one thing to know first: none of these tests is a verdict on its own. Each failing test adds a score, two thresholds decide what the total means, and three kinds of session are never tested at all: an authenticated session, a sender or IP on the anti-spam white list, and any session from an IP range with spam protection switched off.
Where the decisions are made
Everything happens in one of two moments: before the body (at
MAIL FROMorRCPT TO) and after the body (afterDATAor the lastBDAT). The pre-transmission tests run atMAIL FROMby default:DNSBLChecksAfterMailFromdefaults to1, and0moves them to the firstRCPT TO, which leaks less to an address-probing client but accepts more of the conversation first. A session from a configured incoming relay has both phases deferred to afterDATA.Who is never tested.
SMTPConnection::GetDoSpamProtection_returns false the moment the session is authenticated, so your own users' outbound mail is never scored; the sending limits and rate limits are the controls for that. A sender or IP on the anti-spam White list skips the tests entirely, not merely the scoring: SPF is not evaluated, noAuthentication-Resultsverdict is recorded and no reason header is written.The read-only overview. Spam & virus filtering → Spam filtering overview in the Control Panel (Windows only) shows on one screen which checks are on, what each scores, what the thresholds then do, and which checks are switched on but cannot run.
The score and the two thresholds
Both thresholds are on Spam & virus filtering → Anti-spam settings → General.
Setting Default At or above it 0meansAntiSpam.SpamMarkThreshold5 Delivered but tagged: X-hMailServer-Spam: YES,X-hMailServer-Reason-*headers and, optionally, a subject prefixNever mark AntiSpam.SpamDeleteThreshold20 Refused during the conversation, or quarantined if quarantine is on and the verdict came after the body Never refuse AntiSpam.MaximumMessageSize1024 KB Post-transmission tests are skipped for a larger message No limit of its own; the MIME parser's 80 MB ceiling still applies The higher of the two thresholds is also the early-out:
SpamTestRunner::RunSpamTeststops calling tests once the running total reaches it, which is why a message condemned by the blocked-senders list never pays for a DNS lookup. With both thresholds at 0 the early-out is skipped, because greylisting's SPF bypass needs the SPF result and SPF is the sixth test.With
AddHeaderSpamandAddHeaderReasonboth on (the defaults), a marked message carries:X-hMailServer-Spam: YES X-hMailServer-Reason-1: Blocked by SPF. (example.com does not designate 203.0.113.9) - (Score: 3) X-hMailServer-Reason-2: Rejected by Spamhaus. - (Score: 3) X-hMailServer-Reason-Score: 6 Subject: [SPAM] Your invoiceOnly failing tests get a
Reason-Nline.X-hMailServer-Reason-Scoreis the sum of the failing tests, and withAddHeaderReasonoff it is not written at all. The subject prefix is off by default; its text is[SPAM](antispamprependsubjecttext).Start by tagging, not deleting. The wiki's advice is a fortnight with the delete threshold at
0, reading what got tagged, before turning deletion on well above anything legitimate has scored.Every test, in the order it runs
This is the registration order in
SpamTestRunner::LoadSpamTests; nothing reorders it at runtime. Tests 1 to 6 run before the body, 7 to 12 after it.# Test Switched on by Default Default score 1 Blocked senders a non-empty Blocked senders list list empty 100 on a new entry 2 DNS blacklists an active row on DNS blacklists two rows, both inactive 3 3 HELO host AntiSpam.CheckHostInHelooff 2 4 PTR record AntiSpam.CheckPTRoff 1 5 Sender MX AntiSpam.UseMXChecksoff 2 6 SPF AntiSpam.UseSPFoff 3 7 SURBL an active row on SURBL servers one row, inactive 3 8 DKIM AntiSpam.DKIMVerificationEnabledoff 5 9 ARC AntiSpam.ArcFilteringEnabled, a trusted-sealer list and DMARC onoff minus the DMARC failure score 10 DMARC AntiSpam.DMARCEnabledon 5 11 SpamAssassin AntiSpam.SpamAssassinEnabledoff 5, or the merged score 12 Filter hook a non-empty FilterHookUrlempty the engine's score; 100 for a reject DMARC is the only test on by default, and at 5 a DMARC failure marks a message without refusing it. That is the shipped posture: tell the recipient, do not destroy the mail.
What makes a test fail matters as much as its score. SPF scores only a hard
Fail. DKIM scores onlyPermFail; a message with no signature isNone, not a failure. DMARC scores ap=rejectorp=quarantinepolicy the message failed and, separately, a message with more than oneFromheader field;p=nonefailures are logged and score nothing. The blocked-senders list never matches the null sender, and its550says only "Sender address is blocked." without naming the entry. Every DNS-backed check fails open: a lookup that does not complete is read as "not spam". Since 6.3.7 a lookup that fails is a failure, not a name with no addresses: the HELO and PTR tests no longer score a name they could not look up, a DNS blacklist and SURBL no longer read a failed lookup as "not listed" (the blacklist says so in the TCP/IP log and, at most every 15 minutes, the application log), and a DKIM selector that is a CNAME whose query failed isTempFail, notPermFail, so it no longer scores.Greylisting
Greylisting is not a score. It is a temporary refusal of a triplet (sender address, recipient address, connecting IP) this server has not seen before. The settings are on Anti-spam settings → Greylisting.
Setting Default Meaning AntiSpam.GreyListingEnabledoff Master switch AntiSpam.GreyListingInitialDelay30 minutes How long a new triplet is refused for AntiSpam.GreyListingInitialDelete24 hours An unconfirmed triplet is forgotten after this AntiSpam.GreyListingFinalDelete864 hours (36 days) A confirmed triplet's expiry, pushed forward on every accepted message AntiSpam.BypassGreylistingOnSPFSuccesson Needs the SPF test enabled and to have run AntiSpam.BypassGreylistingOnMailFromMXoff Costs an A and an MX lookup per message A greylisted recipient gets
451 Please try again lateratRCPT TO; when the envelope sender is empty the refusal is postponed to the end ofDATAand answered451(docs/Greylisting.md; the wiki prints450), because an empty sender atRCPT TOis very often another server's callout. Greylisting is skipped for a recipient domain with Enable greylisting for this domain unticked, for an IP on the greylisting white list, and for a sender or IP on the anti-spam white list. The wiki records thatGreylistingEnabledDuringRecordExpiration=0did nothing at 6.2.28, so greylisting stays in force during the expiry sweep whatever it says.Hardened since 6.3.4 (schema 6072; docs/Greylisting.md

- The triplet key no longer truncates. Addresses used to be stored cut to 200 characters, so two long addresses sharing their first 200 were one triplet. Each is now keyed by an MD5 digest of the whole address with its domain lower-cased. This is the one change at the defaults: on PostgreSQL, and on MySQL with a binary collation,
[email protected]and[email protected]were two triplets and are now one, so a sender waits once less, never once more. Old rows are not rewritten at upgrade. - A sliding wait and an abuse lock, both off. With
GreyListingSlideOnEarlyRetryon, each retry before the window opens moves the window to now plus the initial delay.GreyListingAbuseThreshold(0; the operator who asked for it uses 20) is the attempt answered550 5.7.1 Too many delivery attempts before the greylisting delay had passed. ..., with the triplet locked forGreyListingAbuseLockMinutes(60). It counts attempts, not retries: a server delivering twenty queued messages to one recipient down one connection makes twenty attempts in seconds. A triplet that has passed once is never refused. Clear greylisting triplets lifts every lock, at the cost of greylisting every sender once more. - The greylisting bypass list (
/api/v1/greylisting-bypass, tablehm_greylisting_bypass
a domain such as example.com, or a suffix such as.mail.example.com, matched on the envelope domain, the HELO host or either, passes greylisting only when SPF, DKIM or DMARC passes for that name. At least one requirement is needed. An entry requiring DKIM or DMARC cannot be judged atRCPT TO, so its greylisting runs afterDATA, where a451or550ends the transaction for every recipient. The test an entry requires must be switched on: an entry requiring DKIM while DKIM verification is off (the default), or DMARC while DMARC is off, can never be satisfied, so the message is greylisted atRCPT TOas if the entry were not there; for an entry matched on the HELO, the SPF check of the HELO name is made only while SPF is switched on. It skips greylisting only; every spam test still runs.BypassGreylistingOnSPFSuccess, by contrast, covers every SPF pass in the world, a hijacked mailbox at a large provider included.
DNS blacklists and SURBL
Spam & virus filtering → DNS blacklists seeds two rows, both inactive until you tick them:
DNS host Expected result Reject message Score zen.spamhaus.org127.0.0.2-8\|127.0.0.10-11Rejected by Spamhaus. 3 bl.spamcop.net127.0.0.2Rejected by SpamCop. 3 The expected-result field takes
|for alternatives, a range on the last octet and wildcards; a malformed range is errorHM5342. Every lookup, match or not, is written to the TCP/IP log, which is how to prove a listing to a sender who disputes it:DNS lookup: 9.113.0.203.zen.spamhaus.org, 1 addresses found: 127.0.0.4, Match: 1The wiki warns that public mirrors of the large lists rate-limit or refuse resolvers that use a public DNS service; if a list stops matching, check its operator's terms first.
SURBL checks the links in the body, so it runs after
DATA. Collection stops once more than 15 distinct addresses are found, the run for one list aborts after 10 seconds, and, to 6.3.6, the first failed lookup abandoned the rest of the list; since 6.3.7 a failed lookup is a failure rather than "not listed", and SURBL goes on to ask the message's other names. One row is seeded inactive:multi.surbl.org, "Rejected by SURBL.", score 3.SPF, DKIM, DMARC and ARC
SPF (
AntiSpam.UseSPF, off, score 3). Evaluation is bounded at 10 DNS-querying terms and atSpfVoidLookupLimitvoid lookups (default 2;0switches that limit off). Since 6.3.4 the evaluator follows RFC 7208, ported from upstream hMailServer, in place of the RFC 4408 library the server carried:6.3.3 and earlier Since 6.3.4 DNS Its own lookups; DNSServer, the cache and the timeout were ignored on WindowsThe server's own resolver settings apply Linux Every check was TempError(HM6406), so DMARC lost its SPF halfWorks Loopback clients 127.0.0.0/8and::1passed before any policy was readNo exemption Authentication-ResultsEverything but passandfailwritten asneutralEach of the seven results under its own keyword Nothing is scored differently: only a fail scores, as before. The loopback row is the one to check when upgrading. CHANGELOG says that where the SPF test or DMARC runs for a loopback client, mail from a domain whose policy does not name the address is judged like any other, so a content filter that re-injects mail should authenticate, or connect from an IP range with anti-spam off.
DKIM (
AntiSpam.DKIMVerificationEnabled, off, score 5). RSA keys shorter than 1024 bits are refused outright, andrsa-sha1signatures are invalid unlessDkimAcceptSha1=1.DMARC (
AntiSpam.DMARCEnabled, on, score 5). More than oneFromfield is scored before any alignment is computed, because DKIM signs the lastFromwhile the header reader answers with the first.ARC (
AntiSpam.ArcFilteringEnabled, off;AntiSpam.ArcTrustedSealers, empty). Its only output is an offset of exactly minus the DMARC failure score, applied when a chain whose every sealer is trusted validates and DMARC is about to fail. With the list empty it does nothing, deliberately: anyone can fabricate a chain and seal it with their own keys. Matching is exact.Since 6.3.4: policy the score cannot express (schema 6073; all off by default; docs/SmtpPolicy.md

Setting What it does UseSPFSoftFailScore,UseSPFTempErrorScore,UseSPFPermErrorScoreScores of their own for SoftFail ( ~all), TempError and PermError.0is "not scored", as beforeSPFTempErrorDeferAnswers a TempError with 451 4.4.3, so a resolver blip defers the message. Never a451on PermErrorRejectMultiRcptNullSenderA null sender's second and every later distinct recipient, and its DATA, are refused550 5.7.1. A single-recipient null sender is never touchedBanMultiRcptNullSender,BanMultiRcptNullSenderHoursAlso bans the address through the auto-ban, once per session, for 24 hours by default (1 to 8760); never an address on AutoBanNeverBanor an incoming relay. Does nothing whileRejectMultiRcptNullSenderis offThe domain white and black list (Spam & virus filtering → Domain white and black list;
/api/v1/domain-policy-list) is keyed by the envelope domain or the HELO suffix rather than by IP, for the correspondent whose sending hosts change every week. It is consulted atMAIL FROMfor unauthenticated sessions of a range that runs the spam tests. Black is550 5.7.1 Mail from <name> is refused by this server's policy.before anything else runs. White skips greylisting, is not deferred for a TempError and is not refused or quarantined on the score, while every test still runs and the mark threshold still marks. It never overrides authentication. The list is ASCII, so a U-label such asbücher.exampleis refused, andhmctlhas no verb for it.SpamAssassin and the filter hook
hMailServer speaks the spamd protocol over TCP to any SpamAssassin daemon, on this machine or on a Linux host. Set
AntiSpam.SpamAssassinHost(127.0.0.1) andAntiSpam.SpamAssassinPort(783) and press Test SpamAssassin connection.AntiSpam.SpamAssassinMergeScore(off) uses the integer part of SpamAssassin's ownscore=in place of the fixedAntiSpam.SpamAssassinScore(5). The timeout moves betweenSAMinTimeoutandSAMaxTimeout(30 and 90 seconds) with load.SpamAssassinLearnOnMove(off) tells spamd that a message moved or copied into Junk is spam, and one moved out of it ham, with spamc's TELL, which spamd refuses unless it was started with--allow-tell. An unresolvable host isHM5507; a scan that does not finish in time isHM5508, and the message is accepted with no verdict; a message that cannot be reloaded after the scan isHM5509and is left as SpamAssassin wrote it.FilterHookUrlputs rspamd, or anything answering JSON over HTTP, in the path of every accepted message;http://127.0.0.1:11333/checkv2needs no adapter.FilterHookTimeoutSecondsis 10, and withFilterHookFailClosed(off) turned on an unanswered check scoresFilterHookRejectScore(100) and reportsHM5541.Quarantine, and what a refused sender sees
Quarantine (
QuarantineEnabled, off;QuarantineRetentionDays, 30) changes what the delete threshold does after the body: the message is answered250 Queued for deliveryand held on Spam & virus filtering → Quarantine. A verdict reached before the body has no message to hold, so it stays a refusal, and a quarantine that fails to store falls through to refusing, so a spam refusal never becomes silent deletion. Since 6.3.4 the quarantine also holds what a mail flow rule sends there (Rule: <name>), what impersonation protection holds and what a recipient's blocked-senders list holds.Per-account overrides, on the account dialog's Spam tab, re-judge that account's own copy at delivery. They only read
X-hMailServer-Reason-Score, and only while Add X-hMailServer-Reason header is on; with it off the value could be the sender's own, so the overrides decline to act.Moment Client sees Score over delete threshold, before the body 550 5.7.1 <text of the first failing test>Score over delete threshold, after the body 554 5.7.1 <text of the first failing test>Same, but quarantined 250 2.0.0 Queued for deliveryGreylisted, real sender 451 Please try again later.Greylisted, null sender 451at end ofDATA(the wiki prints450)Per-test timings go to the debug log (
Spam test: SpamTestSPF, Score: 3, Time: 41 ms); a test taking 10 seconds or more is promoted to the application log. Because every DNS-backed check fails open, a resolver that has stopped answering looks like a run of clean mail, so DKIM, DMARC and SURBL, and since 6.3.7 a DNS blacklist, each write one application-log line at most every 15 minutes when their lookups stop completing.A configuration that works
The wiki's order for a small server:
- Leave the thresholds at 5 and 20 and leave DMARC on. Watch for a fortnight.
- Activate
zen.spamhaus.org(score 3). - Turn on SPF (score 3) and DKIM verification (score 5). With a DNSBL hit they reach 11, still under the delete threshold.
- Turn on
AuthenticationResultsEnabled, so every delivered message records what the server concluded. - Add greylisting if your users can tolerate a first-message delay, leaving bypass on SPF success on.
- Only then add SpamAssassin or an external engine, and consider raising the delete threshold rather than lowering it.
What this topic does not cover, and where to read more
The per-recipient allow and block lists, the quarantine digest, spam traps, country blocking and impersonation protection are in allow and block lists, digests and spam traps, and viruses in viruses and dangerous attachments. The other direction is Being trusted by the servers you send to. The Control Panel and COM are Windows-only; the 6.3.4 switches are also on the Settings view of the Control Deck and
PUT /api/v1/settings/antispam.- Wiki: https://gitlab.com/hmailserver/hmailserver/-/wikis/Stopping-Spam
- https://gitlab.com/hmailserver/hmailserver/-/blob/v6.3.4/hmailserver/docs/Greylisting.md
- https://gitlab.com/hmailserver/hmailserver/-/blob/v6.3.4/hmailserver/docs/SmtpPolicy.md
- Public documentation: https://www.progressiverobot.com/hmailserver-documentation/#10-stopping-spam and https://www.progressiverobot.com/hmailserver-documentation/#265-the-anti-spam-pipeline
- The 6.3.4 security announcement and Upgrading to 6.3.4
- The triplet key no longer truncates. Addresses used to be stored cut to 200 characters, so two long addresses sharing their first 200 were one triplet. Each is now keyed by an MD5 digest of the whole address with its domain lower-cased. This is the one change at the defaults: on PostgreSQL, and on MySQL with a binary collation,
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login