Search Our Database

How to Flush Mail Queue and Remove Frozen Emails in Exim

Last updated on |
by

Introduction

Exim is a widely used mail transfer agent (MTA) on Unix-like systems, known for its flexibility and high configurability. One of its core components is the mail queue, which temporarily stores email messages waiting to be delivered. Over time, especially on busy mail servers or misconfigured systems, the mail queue can become congested with undelivered or “frozen” messages—emails that have repeatedly failed delivery and are no longer being retried.

Frozen emails are typically the result of issues such as unreachable recipients, misconfigured domains, spam filtering, or transient network errors. These messages remain in the queue indefinitely unless manually removed, consuming server resources and potentially affecting email delivery performance. Periodically flushing the mail queue and cleaning up frozen messages is a best practice for maintaining mail server hygiene and performance.

System administrators, DevOps professionals, and hosting providers are most likely to encounter this need when managing email servers or troubleshooting mail delivery failures. This guide provides a comprehensive step-by-step walkthrough on how to safely flush the Exim mail queue and remove frozen messages from it. It also highlights how to inspect the queue, verify Exim’s configuration, and avoid unintended data loss.

It is important to note that removing emails from the queue, especially frozen ones, is a non-reversible action. Before clearing messages, administrators should confirm that no critical or valid emails will be deleted. This article assumes Exim is already installed and configured as the system’s primary MTA.

 

Prerequisites

  • A Linux server running Exim (version 4.x)
  • Root or sudo access to the server
  • Exim command-line utilities (exim, exim -bp, exiqgrep, etc.)
  • Optional: Basic knowledge of Exim configuration and mail logs

 

Step-by-step Guide

Step 1: View the Current Mail Queue

List all messages currently in the Exim mail queue:

exim -bp

Or use mailq as a shortcut:

mailq
  • This displays message IDs, sizes, timestamps, and recipient addresses.
  • Frozen messages are marked with the label *** frozen ***.

 

Step 2: Flush the Mail Queue

Flushing forces Exim to retry delivering all queued messages immediately:

exim -qf

To run it in the background:

exim -qff &
Tips 🖊️: Use -qff to force delivery even if a message is marked as frozen (though Exim typically skips frozen messages).

 

 

Step 3: Remove All Frozen Emails

To remove all frozen messages from the queue:

exiqgrep -z -i | xargs exim -Mrm

Breakdown:

  • -exiqgrep -z -i : Filters only frozen messages and returns their IDs.

  • -xargs exim -Mrm : Removes each message by ID.

 

Step 4: Remove Specific or Old Messages (Optional)

  • To remove messages older than 7 days:
exiqgrep -o 604800 -i | xargs exim -Mrm

Where 604800 is the number of seconds in 7 days.

 

  • To delete a specific message by ID:
exim -Mrm <message-id>

Replace <message-id> with the actual ID from the queue.

 

Step 5: Verify Queue is Clean

After removing messages, confirm the queue is empty:

mailq

If there are no messages, Exim should return:

Mail queue is empty

 

Conclusion

Managing the Exim mail queue is essential for maintaining a reliable and efficient email delivery system. This guide outlined how to inspect the Exim mail queue, flush pending messages, and remove frozen or outdated messages safely. These practices help prevent queue backlogs, conserve system resources, and ensure smoother mail handling on the server.

Regular queue monitoring and maintenance can help identify configuration issues, spam abuse, or system performance bottlenecks before they escalate into larger problems.

Should you have any inquiries about the guidelines, please feel free to open a ticket through your portal account or contact us at support@ipserverone.com. We’ll be happy to assist you further.