Any mail server that accepts logins on a public submission port will be attacked, usually within hours of appearing in internet scans. Automated tools try thousands of passwords against known usernames (brute force), try one common password across many accounts (password spraying) or replay username and password pairs leaked from other services (credential stuffing). When one succeeds, the attacker does not need to break anything else: your server will relay their spam as if it were your customer's mail, your IP addresses land on blocklists and the legitimate user loses access. Defence is a layered job. No single control stops everything, but a handful of inexpensive measures remove most of the risk. This guide explains what the attacks look like, how to recognise them in logs, the layers of protection, how to respond when an account is compromised and how to test your setup. For the client side of authentication see authentication methods and 535 authentication errors.
What the attacks look like
| Pattern | Description | Where you see it |
|---|---|---|
| Brute force | Many attempts against one account from one or a few IP addresses | Hundreds of "authentication failed" lines for one user in minutes |
| Password spraying | One or two likely passwords tried against many accounts, slowly | Few failures per account but many accounts, often from many IPs |
| Credential stuffing | Leaked pairs from other breaches tried against your service | Mostly valid usernames, a low failure rate and occasional successes |
| Distributed attack | Thousands of IPs, each trying only a few attempts | Per-IP limits do not trigger; look at per-account and global counts |
| Successful login followed by abuse | Attacker logs in and sends bulk mail | Sudden outbound volume, new recipient domains, queue growth. See mail queue management |
# Postfix log examples (format varies)
postfix/smtpd[2211]: warning: unknown[198.51.100.77]: SASL LOGIN authentication failed: UGFzc3dvcmQ6
postfix/smtpd[2211]: warning: unknown[198.51.100.77]: SASL LOGIN authentication failed: UGFzc3dvcmQ6
# Count failures per source in the last hour
grep "authentication failed" /var/log/mail.log | awk -F'[][]' '{print $2}' | sort | uniq -c | sort -rn | headLayer 1: Make guessing hopeless
- Unique, long, random secrets. For application accounts, generate 20 or more random characters and store them in a secrets manager. Do not reuse passwords from other systems. For people, enforce length over complexity and block known-breached passwords.
- Do not use predictable usernames such as admin, info or test with weak secrets. Remove default and demo accounts.
- Separate credentials per application, so that a leak is contained and revocation is easy. Prefer API keys or per-app SMTP credentials to shared user mailboxes. See API key security and rotating a key.
- Use stronger authentication where available: OAuth 2.0 tokens instead of passwords for mailbox sending (see SMTP OAuth 2.0), and multi-factor authentication for any web interface.
- Require TLS before AUTH. Credentials should never cross the network in clear text. See TLS for email.
Layer 2: Limit attempts
| Control | How it works | Notes |
|---|---|---|
| Per-IP rate limit | Allow only a few failed logins per IP per minute, then delay or block | Easy to evade with many IPs, but removes simple attacks |
| Per-account lockout or delay | After N failures, slow responses or temporarily lock the account | Avoid permanent lockouts that let attackers deny service to real users; use increasing delays |
| Global failure alarm | Alert when total failures exceed a baseline | Catches distributed attacks |
| Fail2ban or equivalent | Watches logs and adds firewall blocks for abusive IPs for a period | Tune thresholds; whitelist your own networks. Use short and escalating bans |
| Connection limits | Cap simultaneous connections per client | Reduces resource exhaustion. See connection pooling for legitimate high-volume clients |
| Tarpit / delay on failure | Add a delay to failed responses | Slows brute force with little effect on real users |
Layer 3: Reduce exposure
- Restrict by network. If your applications send from known addresses, allow the submission port only from those. See SMTP IP allowlists.
- Use non-public endpoints for internal systems: private networks, VPN or private links.
- Disable unused ports and protocols such as legacy plaintext ports, and close POP or IMAP if you do not need them on the public internet.
- Use separate submission and receiving servers so that an attack on one does not affect mail intake.
- Hide details in banners and error messages, which should not reveal whether a username exists. Return the same response for unknown users and wrong passwords.
- Keep software patched and review configuration for open relay: authentication is not the only way in. See which SMTP port to use.
Layer 4: Limit the damage of a successful login
Assume some account will be compromised eventually, and make it hard for the attacker to benefit:
- Per-account sending limits: messages per hour and per day, and recipients per message. An account that normally sends 50 messages should not be able to send 50,000.
- Per-account sender restrictions: only allow the account to use its own From addresses.
- Outbound content and rate monitoring: detect sudden spikes, many new recipient domains and bursts after hours.
- Automatic suspension of an account on strong anomalies, with notification to the owner.
- Separate streams and pools so that abuse on one account does not damage critical mail. See IP pools.
Monitoring and alerting
| Signal | Threshold idea | Action |
|---|---|---|
| Failed logins per account per 10 minutes | More than 10 | Investigate; slow or lock |
| Failed logins per IP per minute | More than 5 | Block the IP temporarily |
| Successful login from a new country or network | Any, for sensitive accounts | Notify the owner; require verification |
| Outbound messages per account per hour | Above 3 times the account's normal | Throttle and alert |
| Queue growth | Doubling quickly | Check for abuse. See mail queue |
| Blocklist listings of your IPs | Any | Check with the blocklist check |
| Bounce and complaint spikes | Above baseline | Investigate sender. See abuse mailboxes |
If an account is compromised
- Disable the account or revoke the credential immediately.
- Stop the outflow: hold or delete queued spam by ID after review.
- Rotate secrets for the account and anything it could reach, and look for other accounts with the same password.
- Check the damage: blocklists, bounce and complaint rates, reports to the abuse mailbox.
- Find the cause: reused password, leaked key in a repository, malware on a client, weak default.
- Notify the owner, and affected customers where required.
- Restore with a new strong secret and tighter limits, and document what you learned. See account compromise response and reputation recovery.
Testing your defences
Check your own logs weekly for failed-login patterns. In a test environment, run an authorised brute-force test against a dummy account to confirm that rate limits and bans trigger and that legitimate users are not locked out. Verify that alerts reach a human, and rehearse the compromise procedure so that disabling an account and clearing the queue takes minutes. Review settings after every software upgrade or configuration change, because defaults sometimes reset.
Strong secrets, sensible limits and good monitoring turn a noisy, constant background attack into a non-event. The aim is not to stop every attempt but to make sure that no attempt leads to a spam run.
Send with protected infrastructure Per-credential limits and abuse monitoring on our relay.
References and further reading
Frequently asked questions
How do I tell a brute-force attack from normal failed logins?
Look for many failures per account or per IP in a short time, or many accounts with few failures each. Compare to your baseline.
Is fail2ban enough?
No. It helps against simple attacks, but distributed attacks need per-account limits, strong secrets and monitoring.
Should I lock accounts after failed attempts?
Use increasing delays or temporary locks, not permanent ones, so attackers cannot lock out real users.
What should I do first when an account is compromised?
Disable the credential, stop and review the queue, rotate secrets and check blocklists.
Can OAuth reduce this risk?
Yes. Tokens are scoped and expire, so a stolen password alone does not grant SMTP access where basic authentication is disabled.