25,000 spam emails a day from our own mail server: how we fought back when the free tier couldn't
Stolen SMTP passwords, a rate limiter that never fired, a webmail that had to be trusted, and the Haraka plugins we wrote to make 'send spam' structurally impossible.
Disclosure: Published by Solution Market. This is a post-incident write-up about a mail server we run for our own services. Domains, hostnames, accounts and addresses are deliberately omitted or replaced with examples.
It started with a bounce.
A customer-facing app tried to send an ordinary verification email to a Gmail address, and Gmail answered:
550 5.7.1 ... UnsolicitedMessageError
Gmail was not complaining about that one message. It was complaining about us. When we looked at the outbound side of our self-hosted mail server, the reason was obvious: it had been relaying on the order of 25,000 messages a day that none of our applications had written.
This is the story of how that happened, why the off-the-shelf box could not stop it, and the plugins we ended up writing so that the server cannot be talked into sending spam again, even by someone holding a valid password.
The setup: a mail server in a box
We run poste.io, a popular "full mail server in one Docker container". Inside it:
- Haraka, a Node.js SMTP server, receives and sends mail.
- Dovecot stores mailboxes and verifies passwords.
- Rspamd scores messages for spam.
- Roundcube provides webmail.
It is a great way to host mail for several domains without assembling five services by hand. One server handles mail for a handful of our own products, each with a service account that its web application uses to send verification and notification email.
Here is the uncomfortable detail. On poste.io's pricing page, the free edition is "for personal use only", and features such as outbound spam block, the delivery log viewer and mailserver diagnostics are listed as Pro features. We were running the free image. The one switch that was designed for exactly this situation was not in the box we had, and we did not have the delivery logs that would have made the abuse obvious earlier.
To be clear, the free tier did not "cause" the incident. But it set the terms of the fix: whatever protection we wanted, we would have to build into the SMTP pipeline ourselves.
What the attackers sent
The quarantined queue was a small museum of modern phishing. Two campaigns dominated, and we later turned them into detection rules:
- A blockchain-explorer notification template: thousands of copies of a fake "transaction notification" email, impersonating a well-known blockchain explorer. Our rules note more than 5,400 samples.
- A Dutch-language bank phish: messages titled along the lines of "Laatste waarschuwing" ("final warning") about a bank app being "no longer compliant" with PSD2 rules. More than 3,000 samples.
One trick was new to us. Many subjects began with the recipient's own username, like jdoe1!Laatste waarschuwing: ... sent to jdoe1@.... It makes the message feel personal. No legitimate system we know formats subjects that way, which made it one of the most reliable signals we found.
Others impersonated exchanges, wallets, big tech and banks in the display name ("Coinbase" or "PayPal" in front of an address on our domain), with a Reply-To pointing somewhere else entirely.
Five holes, lined up
The investigation found no single dramatic exploit. It found five ordinary weaknesses that happened to line up:
- Stolen SMTP credentials. Three service accounts, the ones our web applications use to send mail, had their passwords taken. How they leaked was never conclusively established; the server only proves that the correct passwords were used from the wrong places.
- A rate limit that never fired. We had a per-account sending limit. Because of plugin execution order and a Redis connection mismatch, it did not actually run on the path the attackers used. It existed in code and in our heads, nowhere else.
- Trust for authenticated and local senders. The spam scanner skipped checks for authenticated, relayed and localhost traffic. Reasonable for a friendly office server; fatal once an attacker is authenticated.
- A filter that failed open. A phishing check let messages through when it hit an error.
- The internal network was trusted for unauthenticated relay.
Each item alone is a minor misconfiguration. Together they turned three leaked passwords into a phishing cannon with a good sending reputation, until it no longer had one.
The conflict with webmail
Our ordinary mailboxes send through Roundcube. Like most webmail, Roundcube connects to the SMTP server from localhost. That is exactly why so many mail stacks quietly treat localhost as special. Poste.io's own authentication plugin carries the comment "we will prevent situation when someone is coming from localhost and limits don't apply", which tells you how often that goes wrong.
So we had a design tension. The webmail must be able to send. But "trusted because it comes from this machine" is a gift to anyone who gets code running on that machine.
That is not a hypothetical worry for Roundcube in particular. It is one of the most attacked webmail clients on the internet:
- CISA's Known Exploited Vulnerabilities catalog lists CVE-2025-49113, a post-authentication remote code execution through unsafe deserialization, added in February 2026 alongside an SVG-based cross-site scripting flaw, CVE-2025-68461.
- Canada's Cyber Centre noted that an earlier XSS (CVE-2024-42009) had been used to obtain valid credentials, which could then enable that RCE.
- In September 2026 a pre-authentication SQL injection in a bundled plugin, CVE-2026-48842, was reported as actively exploited, with Shadowserver counting more than 523,000 internet-exposed Roundcube instances.
We have no evidence that our webmail was the entry point in this incident. But the lesson was clear: a webmail process sitting next to your SMTP server is part of your attack surface, and so is the PHP it runs on. The webmail in our image runs on PHP 7.4, which is past end of life, so we mount a separately patched PHP build into the container and keep it across rebuilds. Then we removed every form of "trusted because local" from the sending path, and gave webmail an explicit, limited identity like everything else.
First, stop the bleeding
The containment steps were boring on purpose:
- Stop SMTP, keep the queue. We stopped sending without deleting anything.
- Quarantine, do not delete. 5,199 queued malicious messages were moved out of the live spool into an administrator-only directory. They are evidence, and they became our test data.
- Rotate the three passwords.
- Ask before reopening. Nothing went back online until the new rules had been tested.
Then, make "send spam" structurally impossible
Haraka's best feature is that every SMTP step is a hook: connect, mail, rcpt, data_post, queue, and a few on the delivery side. A plugin is a small JavaScript file. Poste.io's setup scripts regenerate their own configuration on start, so we mount our plugins and configs read-only into the container, which prevents the stock setup from overwriting reviewed security settings.
We ended up with a pipeline where every outbound message has to pass several independent gates, and every gate fails closed.
Gate 1: right password, wrong place, no entry
Every sending account is registered with the exact IP addresses of the servers allowed to use it. The check runs before the password is even verified:
const origin = String(connection.remote.ip).toLowerCase().replace(/^::ffff:/, '');
const account = policy.accounts[user];
if (!account || !account.origins.includes(origin)) {
return connection.respond(535, '5.7.8 Authentication not permitted from this source', () => next(OK));
}
Note the ::ffff: line. IPv4 addresses can arrive in IPv6-mapped form, and a check that forgets this is a check an attacker can walk around. After deployment, we tested it for real: the correct stolen password, sent over TLS on ports 25, 465 and 587 from a disallowed address, gets 535.
Gate 2: a rate limit that actually runs
The new limiter lives on the rcpt hook and keeps rolling windows in Redis: 20 recipients per minute, 200 per hour and 2,000 per day per account, 500 per hour per source IP, and at most 30 recipients per message.
The interesting part is that all windows are checked and updated in one atomic Lua script, using Redis's own clock. Rejected attempts do not consume quota, and two parallel connections cannot both squeeze under the limit:
-- simplified
for each window: drop entries older than the window
if count >= limit then return window_index end
for each window: add this recipient with timestamp now
return 0
And if Redis is slow or down, the answer is not "send anyway". It is a temporary failure: 4.7.1 Rate limit unavailable; retry later. That one line is the difference between our old limiter and the new one.
Gate 3: you are who you logged in as
The authenticated account, the envelope sender (MAIL FROM) and the From: header must match exactly. Service accounts also have a registered list of display names, so an attacker cannot put "Coinbase" in front of a legitimate address. Sender and Reply-To headers on service mail must match the account too.
Gate 4: score the scam, not the sender
A header plugin adds up weak signals into a score:
| Signal | Points |
|---|---|
| Brand name in display name, sender domain not that brand's | +8 |
| Subject starts with the recipient's username | +6 |
| Known campaign subject templates | +2 to +8 |
| Reply-To domain differs from From domain | +3 |
| No X-Mailer or User-Agent at all | +1 |
| Date header in an unexpected time zone | +1 |
A score of 10 is rejected, 7 is deferred for review. Accounts that were compromised before stay usable but get lower thresholds (5 and 3), so even a faint scent of the old campaigns trips them.
Rspamd adds rules for the body: a brand mentioned in the text while every link points elsewhere (BRAND_URL_MISMATCH), an authenticated user whose From: header does not match, and X-Mailer values typical of PHP mailer scripts. Service mail may only link to that service's own registered domains; a test message with a base64-encoded outside URL is refused.
One small bug here is worth sharing: our Reply-To rule used an address-parsing API that did not exist in the Rspamd version shipped in the image. On a security path, a rule that silently errors is a rule that silently passes.
Gate 5: sign the message, check the signature at the door
The last gate solves a subtle problem. Checks run when a message is received for sending, but delivery happens later, from a queue on disk. What if something modifies a queued file, or slips a message into the queue without passing the checks?
So at the end of the pipeline, after every gate has stamped the transaction, the server computes a SHA-256 hash of the exact message bytes and signs it, together with sender, recipients, origin and time, using an HMAC key that never leaves the server. At delivery time the hash is recomputed and the signature verified. Missing, expired or mismatched? The message does not leave.
Two Haraka details bit us while building this:
- Haraka adds
DateandMessage-IDheaders after the queue hooks run, which changes the bytes we just signed. We now add them ourselves before hashing. - On the delivery hook,
DENYis ignored. The only way to stop a transmission there isDELAY, so a failed signature delays the message for an hour, and an administrator looks at it.
Gate 6: the firewall does not trust any of the above
Defense in depth means assuming the SMTP software itself could be bypassed. The host firewall allows outbound SMTP only for the delivery user of the mail server. No other process, and no other container on the host, can talk to port 25 on the internet directly. Outbound TLS now requires version 1.2 or newer, never falls back to plaintext because a previous attempt failed, and must be verified for Gmail.
A watchdog runs every 30 seconds. It verifies the integrity of the deployed plugins and configs against a manifest built from reviewed source, re-applies the firewall rules, and stops both SMTP services if anything does not match. We wrote one rule into the README for our future selves: never regenerate the manifest to silence an integrity error you cannot explain.
Fixing the server did not fix our reputation
After all of this, a clean test message, properly signed with SPF and DKIM and sent over TLS 1.3, was still refused by Gmail with the same 550 5.7.1.
That is the part nobody warns you about. Reputation is not a configuration value. Gmail's sender guidelines ask all senders for SPF or DKIM, valid reverse DNS, TLS, and spam rates below 0.3% in Postmaster Tools, plus DMARC for bulk senders. We published a DMARC record (p=none, so legitimate mail is not suddenly rejected), verified the domain in Postmaster Tools and filed Gmail's sender escalation form. Then we stopped sending test mail. Hammering a provider with retries while it is judging your reputation does not help.
Forwarding had its own twist. A mailbox that forwards to Gmail re-sends someone else's message from your server. If that message originally came from Gmail, Gmail sees its own domain arriving from a stranger. We rewrite the envelope with SRS on the forwarding domain and sign the forward with that domain's DKIM key, but Gmail-originated forwards were still refused while our reputation recovered.
What we would tell anyone running their own mail server
- Test the limit, not the config file. Send real mail through every submission port (25, 465 and 587) and watch the limit trip. A rate limit you have never seen fire does not exist.
- Bind service accounts to where they live. If an account is only ever used by one web server, a correct password from anywhere else is an attack.
- Delete every "trusted because local" shortcut. Webmail, localhost and the internal network should authenticate and be limited like everything else.
- Fail closed. If the scanner, Redis or a filter errors, defer the mail. Legitimate senders retry; attackers lose their window.
- Quarantine, don't delete. The spam you caught is your best test suite.
- Watch your webmail. Roundcube and the PHP underneath it need the same patch discipline as anything else on the internet.
- Budget weeks for reputation. The technical fix can take a night. Getting providers to trust you again takes much longer.
The free edition of a mail server is a fine way to get started. Just know which safety switches you did not get, and decide where you are going to build them yourself.
Editorial note: prepared with AI assistance from our internal incident record and the mail server's configuration repository, plus the public sources linked above, checked on 18 November 2026. Code samples are simplified. Figures such as message counts come from our incident records. Vendor pricing and vulnerability details may change; check the linked sources.
About the author
- Official Solution Market account. Solution Market (https://solutionmarket.net/en) is a marketplace of ready-made web solutions. We publish guides about the products we operate and always disclose our affiliation.
Comments
Join the discussionNo comments yet. Be the first to comment.
