GoAdmio

spam

Watch the Postfix mail queue for outbound spam: count it, delete it, or, when it grows past the saved limit, alert the administrator, log the busiest senders, empty the queue, and block outgoing port 25

On this page: Overview · Quick start · Syntax · Arguments · Settings · Output · Examples · Troubleshooting · Details · See also


Overview

A compromised mail account or website often sends spam in bulk, and the unsent messages pile up in the mail queue. /go/spam uses the size of that queue to spot the problem. It has three modes:

Mode Command What it does
Check (default) /go/spam Compares the queue size with the saved limit. Above the limit, it alerts you, and it may also act.
Count /go/spam count Prints the number of messages in the queue.
Delete /go/spam delete Deletes every message in the queue.

The check mode is designed to be run on a schedule. When it acts, it:

  1. alerts the administrator by email and WhatsApp
  2. saves a report of the busiest senders from mailtop
  3. blocks outgoing port 25 with smtp block
  4. deletes the whole mail queue

[!WARNING] Deleting the queue removes all waiting mail, including real mail from your customers. It cannot be undone.


Quick start

# Run the check
/go/spam

# See how many messages are in the queue
/go/spam count

Syntax

/go/spam            # check the queue
/go/spam count      # print the queue size
/go/spam delete     # delete the whole queue

The command writes the call and a timestamp to /var/log/go/spam.log. Run it as root.


Arguments

You type Mode
delete Deletes the whole queue.
count Prints the queue size.
Nothing, or any other word Runs the check.

A mistyped word does not give an error. It runs the check, which may block port 25 and delete the queue when the limits are reached.


Settings

The check reads three values from the Config table in /var/lib/sqlite/config.db.

Setting Meaning
SPAM 0 turns tracking off. Any other number turns it on.
QueueNo The queue size that triggers the alert.
UserLimit 0 or less: send an alert only. Above 0: also take the actions listed in the Overview.

When the queue is not above QueueNo, the check does nothing.

Queue vs. QueueNo UserLimit Result
At or below Any Prints the two lines in Output, nothing else.
Above 0 or less Sends an alert saying "No Action Taken".
Above Above 0 Alerts, saves the sender report, blocks port 25, and deletes the queue.

Output

Check

Queue Count: 1523
Total Emails Sent Today Nov 21: 8841

If the limits are reached, you will also see the sender report from mailtop and Port 25 is closed.

When tracking is off:

Tracking setting is disabled.

Count

Only the number, for example 1523.

Delete

Deleting mail queue...

count, delete, and the "tracking is off" case end with exit status 1. In scripts, read the output, not the exit status.


Examples

# Run the check
/go/spam
# How many messages are waiting?
/go/spam count
# Delete everything in the queue (spam emergency only)
/go/spam delete
# Read today's sender report, written when the check took action
cat /var/log/go/mail/spam-$(date +%F).log
# Review recent calls
tail /var/log/go/spam.log

Troubleshooting

Symptom Likely cause Fix
Tracking setting is disabled. SPAM is 0. Turn tracking on in GoAdmio, or leave it off.
A large queue, but nothing happens The queue is not above QueueNo, or UserLimit is 0 or less, so only an alert is sent. Lower QueueNo, or set UserLimit above 0 for automatic action.
The same "No Action Taken" alert arrives again and again It is sent on every run while the queue stays above QueueNo and UserLimit is 0 or less. Fix the cause, or raise QueueNo.
Outgoing mail stopped after a spam alert The check blocked port 25. It is not unblocked automatically. After the spam source is fixed, run /go/smtp unblock.
Real mail was lost The whole queue was deleted. Not recoverable. Ask senders to resend.
count shows 0, but mail is waiting The count only sees the default short queue IDs. Compare with postqueue -p | tail -1.
integer expression expected SPAM, QueueNo, or UserLimit is missing in the configuration. Set the values in GoAdmio.
tee: ... spam-<date>.log: No such file or directory The folder /var/log/go/mail does not exist. Create it with mkdir -p /var/log/go/mail.
Total Emails Sent Today is 0 /var/log/maillog is missing or empty. Check the mail log.

Details

What the check does

  1. Records the call in /var/log/go/spam.log.
  2. If the argument is delete or count, does that and stops.
  3. Reads SPAM. If it is 0, prints a message and stops.
  4. Counts the messages in the queue and prints the count.
  5. Counts today's status=sent lines in /var/log/maillog and prints the number. This number is for information only.
  6. If the queue is above QueueNo:
    • UserLimit above 0: sends the alerts, saves the mailtop --force report to /var/log/go/mail/spam-<date>.log, and runs smtp block, which sends its own alert too. At the end, deletes the whole queue.
    • Otherwise: sends a "No Action Taken" alert.
flowchart TD
    A["spam [mode]"] --> B{"Mode"}
    B -- "delete" --> D["Delete all queued mail"]
    B -- "count" --> C["Print queue size"]
    B -- "other" --> E{"SPAM = 0?"}
    E -- "Yes" --> F["Tracking is disabled, stop"]
    E -- "No" --> G["Print queue size and sent today"]
    G --> H{"Queue above QueueNo?"}
    H -- "No" --> Z["Done"]
    H -- "Yes" --> I{"UserLimit above 0?"}
    I -- "No" --> J["Send No Action Taken alert"]
    I -- "Yes" --> K["Alerts, mailtop report, smtp block, delete queue"]

Queue count

The count is the number of lines from mailq that start with a queue ID made of the characters 0–9 and A–F. This matches Postfix's default queue IDs. If long queue IDs are turned on, those messages are not counted.

Order of events

The alert says the queue "has been deleted" before the queue is deleted. The sender report is made first, so it reflects the queue as it was.

Files

File Purpose
/var/log/go/spam.log The log of calls to this command
/var/log/go/mail/spam-<date>.log The sender report from the day the check took action
/var/log/maillog The mail log read for today's sent count

See also

Command Description
smtp Block or unblock outgoing port 25, or enable port 26
mailtop Check the most active email accounts in GoAdmio
deletemailqueue Permanently delete every email waiting in the Postfix mail queue
outgoing Report today's outbound mail sessions
subjecttop Report the most common email subjects in the Postfix maillog
undelivered Delete undeliverable emails in GoAdmio
postfwd Build the Postfwd rate-limiting rules
mailpwd Bulk-change passwords for all email accounts of a single domain
email Change the administrator email address GoAdmio uses for notifications