How to View and Clear the Sendmail Mail Queue in Linux
When a mail server sends a large batch of email, a remote recipient is temporarily unreachable, or a misbehaving script floods the MTA, Sendmail stores undelivered messages in its local queue for later retry. Usually you need to handle three tasks quickly: list the queued messages, inspect what is inside a stuck email, and purge either a single message or the entire queue safely.
Sendmail mail queue
Below are the essential commands for managing the Sendmail queue on Linux and Unix systems: listing messages with mailq and sendmail -bp, counting spool files in /var/spool/mqueue/, reading qf* and df* files, forcing delivery, and clearing the queue without corrupting active locks.
How to view the Sendmail mail queue
You can display the current outbound mail queue using either of these equivalent commands:
mailq sendmail -bp
The output lists each message’s Queue ID, size, arrival timestamp, sender, deferral reason, and recipient. An asterisk (*) right after the Queue ID means Sendmail is actively processing that message, and the final line prints the total number of queued requests.
If local scripts submit mail through the Mail Submission Program (MSP), messages can also accumulate in the separate client queue at /var/spool/clientmqueue/. Check it with the -Ac flag:
mailq -Ac
Detailed queue summary and counting spool files in /var/spool/mqueue/
To get more verbose details about queued messages and delivery status, pass the -v flag:
sendmail -bp -v
If you only want the summary line with the total count:
mailq | tail -n 1
When tens of thousands of spam messages back up in the queue, running mailq can be slow. It is much faster to count the qf* header files directly inside /var/spool/mqueue/:
find /var/spool/mqueue -maxdepth 1 -name 'qf*' | wc -l
Each queued message in Sendmail is split into multiple files sharing the same Queue ID (derived from the process ID and timestamp) with a two-letter prefix:
qf*(queue file) – queue control data and message headers: sender, recipients, timestamps, and the latest deferral error.df*(data file) – the message body itself (text and attachments).xf*(transcript file) – temporary SMTP session log created while a delivery attempt is running.tf*(temporary file) – temporary staging file used while updating aqf*file; never delete it while Sendmail is running.
Inspecting a specific queued message
Grab the Queue ID from mailq (for example q4S1AbCd012345, without any trailing *) and list all files belonging to that message:
ls -l /var/spool/mqueue/*q4S1AbCd012345
Read the headers and delivery failure reason in the qf* file (M lines hold the error message, S is the sender, R is the recipient, and H? lines are headers):
less /var/spool/mqueue/qfq4S1AbCd012345
Read the message body in the corresponding df* file:
less /var/spool/mqueue/dfq4S1AbCd012345
Forcing delivery (flushing the queue)
Once network connectivity or a remote relay issue is resolved, you do not have to wait for the next scheduled queue run. Force immediate processing with verbose output:
sendmail -q -v
Instead of flushing everything at once, you can target messages by recipient substring (-qR), sender substring (-qS), or Queue ID (-qI):
sendmail -qRexample.com -v sendmail [email protected] -v sendmail -qIq4S1AbCd012345 -v
How to delete one message or purge the queue safely
Always stop the Sendmail service before deleting or moving files in /var/spool/mqueue/. Deleting spool files while the daemon is running can corrupt an active delivery or leave orphaned df* data files behind.
Stop the Sendmail daemon first (using systemctl or service depending on your OS):
systemctl stop sendmail
On older SysVinit systems or FreeBSD, run:
service sendmail stop
To delete a single message by its Queue ID, remove all files ending with that ID:
rm -f /var/spool/mqueue/*q4S1AbCd012345
If the queue is filled with frozen bounces or spam from a single sender, locate the matching qf* files first:
find /var/spool/mqueue -maxdepth 1 -name 'qf*' \
-exec grep -l 'MAILER-DAEMON' {} +
To clear the entire queue safely, consider moving the spool files to a backup folder first (on the same filesystem this is instantaneous and reversible):
mkdir -p /root/mqueue-backup
find /var/spool/mqueue -maxdepth 1 -type f \
-exec mv -t /root/mqueue-backup {} +
If you are certain the queued mail should be discarded permanently, delete all files inside /var/spool/mqueue/ with find. This avoids the shell’s Argument list too long error on huge queues and preserves the directory permissions:
find /var/spool/mqueue -maxdepth 1 -type f -delete
If local scripts also flooded the submission queue, check and clean /var/spool/clientmqueue/ the same way. Finally, start Sendmail again and confirm the queue is clear:
systemctl start sendmail mailq
Need a Linux VPS to test mail server configurations? On Vultr you can spin up a server with hourly billing and delete it when you are done (affiliate link).