Spam filter and mail antivirus
How rspamd filters incoming mail into Junk or refuses it, what each mailbox can tune (strictness, trusted and blocked senders, a subject tag, auto-block on "mark as spam"), and how virus scanning and dangerous-attachment blocking work.
On this page
Every message that reaches a Berth server passes through a spam filter before it is delivered, and optionally through a virus scanner. Suspicious mail lands in the mailbox's Junk folder; mail that is clearly spam or carries something dangerous is refused while the sending server is still connected, so the sender gets the error and nothing is silently lost. This page explains what happens by default and what each mailbox can adjust.
How filtering works
Berth uses rspamd as a milter in Postfix. For each incoming message it weighs the content, the sending server's reputation and the sender authentication: SPF, DKIM, DMARC and ARC are all checked on arrival. The outcome is one of three:
- Normal mail is delivered to the inbox.
- Suspicious mail is marked as spam and Dovecot files it in the mailbox's Junk folder on delivery. The user can still find it there, and webmail and mail programs show it like any other folder.
- Certain spam is refused during the SMTP session. The sending server keeps the message and tells its own user, so Berth never has to send bounce messages for mail it did not want.
The sending domain's DMARC policy is enforced: mail that fails DMARC for a domain with p=reject is refused during the SMTP session, and with p=quarantine it goes to Junk. Mail that pretends to come from a domain hosted on this server, without passing SPF or DKIM for it, is also filed as spam, even when that domain has no DMARC policy; it lands in Junk rather than being refused, so a forwarded message from a colleague can still be found. Mail sent by logged-in users of this server is not affected.
Greylisting is deliberately off: it delays legitimate first contacts by minutes and adds little against today's spam.
Spam filtering is a separate component (spam). It is installed by default and can be left out with berth install --no-spam; without it, mail is not filtered at all.
Spam settings per mailbox
Open a mailbox on the domain's Mail tab; the section Spamfilter holds its own settings. Without changes, a mailbox uses the server defaults.
- Threshold: make the filter stricter or more lenient for this mailbox. A stricter setting sends more mail to Junk; the server's limit for refusing certain spam stays the same.
- Trusted senders: addresses or whole domains whose mail never goes to Junk, one per line. A trusted sender always wins over a block.
- Blocked senders: a separate page per mailbox where you add, search and remove blocked addresses or domains. Mail from a blocked sender always goes to Junk. The list shows where each entry came from: added by hand, taken over from the old server, or added after "mark as spam".
- Subject tag: optional text placed before the subject of spam, such as
*****SPAM*****, handy for a filter rule in a mail program. The tag is added per mailbox on delivery, so one recipient's setting never changes the subject for others. The message still goes to Junk. - Block the sender when I mark a message as spam: see below.
berth mail account spam --address info@example.com # show
berth mail account spam --address info@example.com \
--allow partner.example.nl --block offers@example.net \
--subject-tag '*****SPAM*****'
berth mail account spam --address info@example.com --unblock offers@example.net
berth mail account spam --address info@example.com --clear # back to defaultsThe --allow and --block flags replace the list; --unblock removes single entries and keeps the rest. When a server is migrated from Plesk, cPanel or DirectAdmin, each mailbox's SpamAssassin preferences are taken over: trusted and blocked senders, the threshold and the subject tag. Rules that cannot be translated are listed rather than silently dropped. See Migrating a server.
Auto-block on "mark as spam"
With Block the sender when I mark a message as spam switched on (it is off by default), moving a message to Junk adds its sender to the mailbox's blocked senders. It works with the Spam button in webmail and with any mail program that moves the message to the Junk folder over IMAP.
A sender is only added when the server could confirm on arrival that the address really belongs to the sending domain. Spam with an invented or forged sender blocks nobody; otherwise innocent people whose addresses were abused would end up on your list. The new entry appears within a few minutes and can be removed again on the blocked senders page.
berth mail account spam --address info@example.com --auto-block
berth mail account spam --address info@example.com --auto-block=falseVirus scanning of mail
When the component Mail antivirus is installed, rspamd hands every incoming message to ClamAV's daemon, clamd. A message with a virus is refused during the SMTP session, with the name of the detection in the error the sender sees.
clamd keeps its virus definitions in memory, about 1 GB. On a new installation the mail scan is switched on when clamd already runs for the upload scan or the realtime malware scan of the webspaces, so it costs no extra memory there. Otherwise add it yourself in System → Software or:
berth component install mail-antivirus
berth install --reconfigure --mail-antivirus # the same, during a reconfigurationThe same ClamAV installation scans websites and uploads; see Malware scanning.
Dangerous attachments
Independently of the virus scan, rspamd refuses mail with an attachment of a type that Windows runs on a double-click or that bypasses its warnings for files from the internet: programs and installers (such as .exe, .scr, .msi), scripts (.js, .vbs, .ps1), shortcuts (.lnk) and disk images (.iso, .img). The check looks inside archives such as zip, rar and 7z, and catches double extensions like invoice.pdf.exe.
The sender gets a refusal that explains why and suggests sharing the file through a download link instead. The rule applies to outgoing mail from mailboxes on the server as well, so a hijacked mailbox cannot spread malware from your IP address.
Protection of the mail ports
The mail services themselves are protected against abuse:
- IMAP, POP3, submission and ManageSieve limit how many connections one IP address (or one IPv6 /64 network) may hold and open, so one client cannot exhaust the server for everyone. An administrator can exempt trusted networks, such as an office behind one NAT address:
berth mail conn-trusted --set 192.0.2.0/24,2001:db8::/48. - Login attempts are rate-limited, and repeated failures from an address are temporarily blocked, including failed logins in webmail. See Firewall and bans.
- Authentication is only accepted over TLS, and a logged-in user may only send as their own address or an alias of it (see Outbound mail).
Related
- Mail authentication: SPF, DKIM and DMARC for your own outgoing mail.
- Outbound mail: what stops a compromised site or mailbox from sending spam.
- Mailboxes: the mail log shows whether a message was refused, deferred or delivered.