Outbound mail and abuse protection
One outbound budget per subscription across every way mail can leave the server, the mail gate in front of PHP's mail(), port 25 closed for sites, per-mailbox limits, an outbound IP address per subscription, and why the sender must match the login.
On this page
On a shared server, the reputation of the outgoing IP address belongs to everyone. One hacked contact form or one stolen mailbox password can get that address on blocklists within an hour, and then nobody's mail arrives at Gmail or Microsoft. Berth is built so that a single subscription cannot do that: all mail that leaves the server is counted against one budget per subscription, and mail that does not fit is refused before it ever enters the queue. And if mail stops leaving the server or its address lands on a blocklist anyway, Berth notices it by itself; see mail delivery checks.
One budget per subscription
Every subscription has one hourly budget for recipients outside the server. It is shared by every path mail can take:
- PHP's
mail()from the subscription's websites; - mailboxes sending through SMTP submission (on top of their own per-mailbox limit);
- forwards and aliases pointing to outside addresses, where each external target counts;
- away messages and forwarding rules from Sieve;
- direct use of
sendmailfrom scripts, cron jobs or SSH sessions; - mailing lists, which ask for room for all members before a message is sent.
When the budget is used up, the server answers with a temporary refusal. A mail program, Dovecot or the sending script tries again later, and once the hour has moved on the mail goes out; nothing is silently dropped. The administrator and, where applicable, the customer get a notification, because a subscription at its limit is often a misused form or a compromised site.
The size of the budget is set per package (berth plan set … --mail-per-hour), can be adjusted per subscription, and has a server-wide default for packages that don't set one. All of these are configurable; -1 means unlimited.
PHP mail() and the mail gate
Whether a site may use PHP's mail() at all is a package setting: berth plan set … --php-mail. It is off by default. Sites can always send through SMTP with a mailbox and password, for example with the WP Mail SMTP plug-in or PHPMailer, and that is the recommended way.
When mail() is allowed, it does not hand mail straight to Postfix. PHP's sendmail_path points to a small wrapper that passes the message to the mail gate, a separate process the customer cannot reach. The gate identifies the calling subscription by the kernel's credentials of the connection, not by anything the script claims, counts the message against the budget, and:
- refuses it before it reaches Postfix when it does not fit, so
mail()returnsfalseand the site sees the error; - otherwise sets the subscription's sender and a header identifying the subscription, and delivers it to Postfix.
If the message's From: names a domain that belongs to another subscription on this server, the gate replaces it with the subscription's own sender and keeps the original address as Reply-To. An outside address, such as a visitor's address in a contact form, is left alone.
If the gate itself is unavailable, mail() returns a temporary error. Uncounted mail never slips through, and the mail queue page shows that the gate is not responding.
Direct sendmail
Scripts that call sendmail directly (through exec, from cron or from an SSH session) also pass through the gate before anything leaves the server: they are attributed to the subscription, counted in the same budget and held in the queue when over it. An administrator who wants to close this path completely can choose strict mode: then only mail() from the PHP pool works, and scripts in cron or SSH must send through SMTP on port 587. Strict mode is off by default because many cron scripts use mail().
Port 25 is closed for sites
Websites, apps and containers cannot speak SMTP on port 25, neither to the local server without logging in nor directly to other mail servers. Without that rule, mail could bypass both authentication and the budget. Sites send through mail() or through a mailbox on port 587.
When a site really needs it, as on Plesk, an administrator can open it for the server. Mail sent that way is outside the budget, so use it only when you must.
Settings on the mail queue page
All of this is managed on Admin → Mail queue, which next to the queue itself shows:
- Outbound mail per subscription: per subscription, how many messages and recipients went out in the last hour, split into
mail(), forwarded, SMTP and lists, and how many were refused. Reset counter clears a subscription's count; Re-enable lifts a stop on direct sendmail. - The switches Site mail() goes through the mail gate (on by default), Subscriptions may not use sendmail directly (strict mode) and Sites may use SMTP on port 25 themselves (open port 25 for sites).
- Mailboxes via SMTP: the busiest mailboxes of the last hour, with their limit.
berth mail local # show the state
berth mail local --per-hour 300 # server default per subscription
berth mail local --strict # only mail() from the PHP pool
berth mail local --site-smtp=false # keep port 25 closed for sites
berth mail local --unblock acme # re-enable sendmail for subscription acme
berth mail local --check # count nowLimits per mailbox and per domain
Mailboxes have their own hourly limit for mail sent through SMTP, so a stolen password cannot use a mailbox as a spam cannon. Above it, the mail program gets a temporary refusal and the administrator gets a notification. The limit has a server default, can be changed per domain under More settings → Outbound limit on the mail page, and per mailbox in the mailbox's own section.
berth mail limit --domain example.com # show
berth mail limit --domain example.com --per-hour 200 # per domain
berth mail limit --domain example.com --address info --per-hour 1000 # one mailbox
berth mail limit --default 250 # server defaultThe sender must match the login
A mailbox that logs in over SMTP may only send as its own address or one of its aliases (including the same name at a domain alias with mail). Relaying without logging in is refused, and authentication is only accepted over TLS. Outgoing mail is signed with the domain's DKIM key only when the sender matches the login or the sending subscription (see Mail authentication).
A site or mailbox can only send under the domains of its own subscription. Mail that claims to come from another customer's domain is not signed with that domain's DKIM key, and its sender is replaced, so one customer can never send mail that passes as another's.
Mail from mail() gets the subscription's own sender, and Sieve forwards and away messages are sent with the mailbox as envelope sender. That keeps SPF aligned at the receiving end.
An outbound IP address per subscription
By default all mail leaves from the server's main address. Two options give a subscription its own reputation:
- A subscription with its own IP address for its sites can send its mail from that address as well (
berth mail own-ip). The card Own IP address per subscription on the mail queue page shows each one, whether it is active, and the result of its checks. - A separate outbound address without its own IP for the sites: under Mail queue → Outbound address, or
berth mail outbound --sysuser … --ipv4 … --ipv6 …. The same page sets the address and HELO name for the whole server.
The HELO name follows the address's PTR record when that points back, otherwise the server's mail hostname. Receivers such as Gmail and Microsoft refuse mail from an address without a matching PTR, or whose SPF record doesn't include it, so the panel checks both regularly and on request:
berth mail own-ip --check
berth mail own-ip --sysuser acme --on
berth mail outbound --checkThe PTR record is set by whoever controls the IP range, usually your hosting provider. The SPF record is managed by the customer, or by the panel when it manages the DNS.
During a migration
When Berth takes over a server, it can send from the old server's address and under its name, so receivers see no change, and it can relay mail for selected domains back to the source server during a rollback (berth mail relay). See Migrating a server.