Managing the Exim mail queue

How to view, monitor, and clean the mail queue on an Exim server.

Exim is a popular Mail Transfer Agent (MTA) used on many Unix-like systems. Every message passing through Exim receives a unique identifier called a Message ID.
Example: 1TrXS1-0003SL-3h

These IDs are used to monitor the queue, view message details, and remove unwanted emails.

Basic Exim queue commands

All commands should be executed as root.

Viewing the Queue

  • Show the total number of messages in the queue:
    exim -bpc
    
  • Display the full list of queued messages (time, size, ID, sender, recipient):
    exim -bp
    
  • View message headers:
    exim -Mvh [ID]
    
  • View message body:
    exim -Mvb [ID]
    
  • View message logs:
    exim -Mvl [ID]
    

Removing Messages

  • Delete a single message by ID:
    exim -Mrm 1TrXgs-0004t8-0W
    
  • Delete all frozen messages:
    exipick -z -i | xargs exim -Mrm
    
  • Delete all messages from a specific sender domain:
    exipick -f @spamdomain.com -i | xargs exim -Mrm
    
  • Delete all messages to a specific recipient domain:
    exipick -r @victimdomain.com -i | xargs exim -Mrm
    
  • Delete all messages in the queue:
    exipick -i | xargs exim -Mrm
    
  • Fast queue cleanup (when there are hundreds of thousands of messages)
    If the queue is heavily overloaded, the fastest way to clear it is:
    rm -rfv /var/spool/exim4/input/
    rm -rfv /var/spool/exim4/msglog/
    sudo systemctl restart exim
    

If you’re using Postfix instead

  • View the mail queue:
    mailq
    
  • Delete all messages in the queue:
    postsuper -d ALL
    

Useful tips

  • Before mass-deleting messages, it’s recommended to back up the /var/spool/exim4/ directory.
  • Regularly monitor the queue with exim -bpc. A constantly growing number of messages is often a sign of a spam attack or misconfiguration.
  • For advanced filtering, use the exipick utility — it allows you to select messages based on various criteria (sender, recipient, age, etc.).

Help

If you have any questions or need assistance, please contact us through the ticket system — we're always here to help!

Updated at:
Need help?Our engineers will help you free of charge with any question in minutesContact us