Security

How do I delete the pending mail in the Exim queue?

To delete pending mail in the Exim mail queue, you need to use Exim’s command-line tools. Here’s a step-by-step guide:

List the Mail Queue: Before deleting any mail, it’s useful to see what’s in the queue.

exim -bp
This command lists all the messages currently in the queue.

Pending mail in the Exim queue

Delete All Messages in the Queue: To delete all pending emails in the queue, use:
exim -bp | exiqgrep -i | xargs exim -Mrm
    • exim -bp lists the queue.
    • exiqgrep -i extracts the message IDs.
    • xargs exim -Mrm removes the messages with the extracted IDs.

Delete Specific Messages: If you want to delete specific messages, first get their IDs using:

exim -bp

Then delete them individually using:

exim -Mrm <message-id>

Replace <message-id> with the actual ID of the message you want to delete.

Delete Frozen Messages: Sometimes you may want to delete only frozen messages (emails that couldn’t be delivered and are not being retried).

exim -bp | grep frozen | awk '{print $3}' | xargs exim -Mrm

This command pipeline finds all frozen messages and removes them.

Additional Tips

  • Check for Exim Version: Ensure you are using the correct commands for your version of Exim. Some commands might slightly differ.
  • Automation with Scripts: If you need to perform this task regularly, consider writing a script and scheduling it with cron.

Here’s an example script to delete all frozen messages, which you can save as clean_exim_queue.sh:

#!/bin/bash
# Script to clean up Exim mail queue

# Delete frozen messages
exim -bp | grep frozen | awk '{print $3}' | xargs exim -Mrm

# Optionally, delete all messages (uncomment the following lines if needed)
# exim -bp | exiqgrep -i | xargs exim -Mrm

Make the script executable:

chmod +x clean_exim_queue.sh

You can then set up a cron job to run this script periodically. For example, to run it every day at midnight, add the following line to your crontab:

0 0 * * * /path/to/clean_exim_queue.sh
By following these steps, you can effectively manage and clean the pending mail in the Exim queue.
To know about How to configure and download raw access logs in cPanel click here.