mailtop
Show which email accounts sent the most mail today (or on an earlier day), update their sent counters, and enforce the server's daily sending limit
- Command:
/go/mailtop - Category: Mail
- Required options: None
- Output: A report with the mail queue size, the number of emails sent, and a table of the busiest accounts
- Log:
/var/log/go/mailtop.log - Last updated: 2026-11-20
On this page: Overview · Quick start · Syntax · Options · Output · Examples · Troubleshooting · Details · See also
Overview
/go/mailtop reads the mail log (/var/log/maillog) and counts how many emails the server sent. It then:
- prints how many emails are waiting in the mail queue
- prints how many emails were sent that day, and a table of the accounts that sent the most
- saves each account's count in GoAdmio (today's total, and one total per weekday)
- acts if the server sends more than its daily limit: it alerts the administrator, saves a report, deletes the whole mail queue, and blocks the SMTP port
The last part is the reason to know this command well. It is an automatic defence against a hacked mailbox or website that starts sending spam. Read The daily limit before changing anything.
The command only counts mail that the server sent out. Incoming mail isn't included.
Quick start
# Today's report
/go/mailtop
# Yesterday's report
/go/mailtop 1
Syntax
/go/mailtop [days-ago] [--cron] [--force]
| Form | Behavior |
|---|---|
/go/mailtop |
Report for today. This is the only form that enforces the daily limit. |
/go/mailtop <n> |
Report for n days ago. Only the digits of the first argument are used. |
/go/mailtop --cron |
Same as a normal run, but exits quietly when the email count hasn't changed since the last run. |
/go/mailtop --force |
Counts every email even if there are more than 5,000. |
Options
| Argument | Notes |
|---|---|
<days-ago> |
A whole number as the first argument. 0 or no number means today. A past day only works while that day is still in /var/log/maillog. |
--cron |
For scheduled runs. If the number of emails is the same as in the previous run, the command ends without printing anything (exit status 1). |
--force |
Needed when more than 5,000 emails were sent. Without it, the command stops with Too many emails (RUN: /go/mailtop --force). Counting is slow, because the log is searched once for every email. |
The lock that prevents two runs at the same time is skipped only when both --cron and --force are given. See Locking.
Output
------------------------------------------
Queue Count (12)
------------------------------------------
Friday, November 20 (386 Emails)
------------------------------------------
Sent Today Email Domain
---------- ----- ------
214 info@example.com example.com
97 sales@example.org example.org
------------------------------------------
45 www-data@server.example.com
30 noreply@example.net
------------------------------------------
| Part | Meaning |
|---|---|
Queue Count (n) |
Emails waiting in the mail queue. Not shown when the queue is empty. |
<date> (n Emails) |
The number of outgoing delivery log lines for that day. |
| Table | The accounts known to GoAdmio that sent mail, busiest first. |
| Second list | Shown only when the table's total is different from the count above. It lists the 10 most frequent sender addresses in the log, including senders that aren't GoAdmio mailboxes, such as website scripts. |
Counting rules
The count isn't the number of messages. It is the number of delivery lines in the log, so:
- a message sent to 10 recipients counts as 10
- every delivery retry counts again
- mail that was addressed to the administrator's email (from the server settings) is left out of the total
Exit status
| Situation | Message | Exit status |
|---|---|---|
| Normal run | The report. | 0 |
| Another run is in progress | Instance (mailtop) already running. |
1 |
--cron and nothing changed |
No output. | 1 |
More than 5,000 emails and no --force |
Too many emails (RUN: /go/mailtop --force) |
1 |
Examples
# Today's busiest accounts
/go/mailtop
# Yesterday's report
/go/mailtop 1
# Count a very busy day
/go/mailtop --force
# Look at the report saved when the limit was exceeded
cat /var/log/go/mail/mailtop-2026-11-20.log
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
Instance (mailtop) already running. |
Another run holds the lock, or an earlier run was interrupted less than 30 minutes ago. | Wait, or delete /usr/local/goadmio/lock/mailtop.lock if no run is active. A lock older than 30 minutes is ignored. |
Nothing is printed with --cron |
The email count is the same as in the previous run. | Expected. |
Too many emails (RUN: /go/mailtop --force) |
More than 5,000 emails today. The sent counters were already reset to 0 and are not rebuilt. |
Run /go/mailtop --force. |
| The numbers look too high | Each recipient and each retry is counted. | See Counting rules. |
| The second list shows addresses that aren't mailboxes | The mail was sent by a website script or by the server itself. | Check the sites involved. subjecttop and outgoing help. |
| The report for an earlier day is empty or too small | The mail log has been rotated and no longer contains that day. | Only the current /var/log/maillog is read. |
Sent Today changed after running for an earlier day |
The command overwrites today's counters with the numbers of the day you asked for. | Run /go/mailtop again to restore today's numbers. |
| The mail queue was emptied and outbound mail stopped | The daily limit was exceeded. | See The daily limit. |
| The limit is never enforced | ServerLimit or UserLimit is 0, or the day's count is above 5,000 and --force wasn't used. |
See The daily limit. |
/var/log/go/mail/mailtop-<date>.log contains Instance (mailtop) already running. |
The report is requested while the lock is still held. See Known limitations. | Run /go/mailtop --force yourself after the lock is released. |
Details
How it works
flowchart TD
A["mailtop [days-ago]"] --> B{"Lock held less than 30 min?"}
B -- "Yes" --> X["Print already running, exit 1"]
B -- "No" --> C["Take the lock"]
C --> D["Count outgoing delivery lines for the day"]
D --> E{"--cron and same count as last run?"}
E -- "Yes" --> Y["Exit 1"]
E -- "No" --> F["Print queue size and email count"]
F --> G["Reset counters"]
G --> H{"5000 or fewer, or past day, or --force?"}
H -- "No" --> Z["Print Too many emails, exit 1"]
H -- "Yes" --> I["Count mail per sender, update counters"]
I --> J["Print table, and top senders if totals differ"]
J --> K{"Today and above the limit?"}
K -- "Yes" --> L["Alert, delete queue, block SMTP"]
K -- "No" --> M["Release the lock"]
L --> M
- Logs the call to
/var/log/go/mailtop.log. - Checks and takes the lock (see Locking).
- Reads the number of days ago from the first argument, and the server's daily limit from the settings.
- Counts the delivery lines for that day in
/var/log/maillog, leaving out lines for the administrator's address. - With
--cron, stops if the count equals the one saved from the last run. Saves the new count. - Prints the queue size, and the day's heading with the count.
- Sets every account's
SentTodayand the weekday counter to0. - If there were 5,000 emails or fewer, or the day is in the past, or
--forcewas given, finds the sender of each delivery line and adds 1 to that account's counters. Otherwise prints the "too many emails" message and stops. - Recalculates each account's weekly total.
- Prints the table of accounts that sent mail. If the table's total is different from the day's count, also prints the 10 most frequent senders.
- Checks the daily limit (today only), and removes the lock.
The daily limit
After the report, a run for today compares the day's count with ServerLimit from GoAdmio's settings. When the count is above it, and both ServerLimit and UserLimit are greater than 0, and no report exists yet for today in /var/log/go/mail/, the command:
- Prints
Email Limit Exceeded (<count>/<limit>). - Emails and WhatsApps the administrator. The message says that the mail queue has been deleted, and where the report is.
- Saves a report to
/var/log/go/mail/mailtop-<date>.log. - Deletes every message in the mail queue, including the deferred ones, with
postsuper -d ALL. Legitimate mail waiting in the queue is lost too. - Blocks the SMTP port with
smtpblock.
It does this once per day, because the report file marks that it has been done. To undo it, find and stop the source of the mail, then run /go/smtp unblock.
The limit check is reached only if the day's count is 5,000 or less, or --force was used. If you rely on this protection, check how the scheduled job calls mailtop (see cron).
Locking
The command takes a lock file, /usr/local/goadmio/lock/mailtop.lock, so two runs don't overlap. A lock newer than 30 minutes stops a new run. An older lock is ignored. The lock is removed when the command ends. It is skipped only when both --cron and --force are given.
Files used
| File | Purpose |
|---|---|
/var/log/maillog |
The mail log that is counted. |
/var/lib/sqlite/mail.db |
The Mail table, with SentToday, one Sent<Weekday> counter per day, and SentThisWeek. |
/var/lib/sqlite/config.db |
The administrator's email, ServerLimit, and UserLimit. |
/usr/local/goadmio/cache/mailtop.db |
The count from the last run, used by --cron. |
/usr/local/goadmio/lock/mailtop.lock |
The lock. |
/var/log/go/mail/mailtop-<date>.log |
The report saved when the limit is exceeded. |
Known limitations
- The saved limit report is probably useless. When the limit is exceeded, the command starts a second copy of itself with
--forceto write the report. The first copy still holds the lock, so the second one printsInstance (mailtop) already running.and stops. The condition that decides whether to take the lock (--cronor--forcemissing) probably should be "and". - The counters are reset before the 5,000 check. If you get
Too many emails, all of today's counters are0until you run--force. - An empty day can add a phantom email. With no outgoing mail, the loop still runs once with an empty ID and can credit one email to the first sender in the log.
- Earlier days overwrite today's counters.
- Only
/var/log/maillogis read, and only the current file. - Slow on busy days. The whole log is searched once per email.
/var/log/go/mail/must exist for the limit report to be saved.- Unused values. The domain and alias lists, the hostname, and a timestamp are read but never used.
See also
| Command | Description |
|---|---|
outgoing |
Report today's outbound mail sessions |
incoming |
List today's messages received by the server's SMTP service |
subjecttop |
Report the most common email subjects in the Postfix maillog |
sasltop |
Report the top 20 sources of SASL LOGIN failures and optionally block them |
smtp |
Manage the SMTP port: block, unblock, and change it |
deletemailqueue |
Permanently delete every email waiting in the Postfix mail queue |
undelivered |
Delete undeliverable emails in GoAdmio |
spam |
Track spam email accounts in GoAdmio |
postfwd |
Build the Postfwd rate-limiting rules |