GoAdmio

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

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:

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:

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
  1. Logs the call to /var/log/go/mailtop.log.
  2. Checks and takes the lock (see Locking).
  3. Reads the number of days ago from the first argument, and the server's daily limit from the settings.
  4. Counts the delivery lines for that day in /var/log/maillog, leaving out lines for the administrator's address.
  5. With --cron, stops if the count equals the one saved from the last run. Saves the new count.
  6. Prints the queue size, and the day's heading with the count.
  7. Sets every account's SentToday and the weekday counter to 0.
  8. If there were 5,000 emails or fewer, or the day is in the past, or --force was 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.
  9. Recalculates each account's weekly total.
  10. 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.
  11. 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:

  1. Prints Email Limit Exceeded (<count>/<limit>).
  2. Emails and WhatsApps the administrator. The message says that the mail queue has been deleted, and where the report is.
  3. Saves a report to /var/log/go/mail/mailtop-<date>.log.
  4. Deletes every message in the mail queue, including the deferred ones, with postsuper -d ALL. Legitimate mail waiting in the queue is lost too.
  5. Blocks the SMTP port with smtp block.

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


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