Loading...

Knowledge Base

VPS or Dedicated: How to Clear the Mail Queue

Are your emails getting stuck? A mail queue issue could cause this. Clearing the mail queue on your VPS or dedicated server is actually quite simple. This article outlines the step-by-step process for clearing the mail queue.

What You Need

  • The root user password on your server.
  • SSH clients like Terminal (Mac, Linux) or PuTTY (Windows).
  • Your server's IP address or a domain name pointing to your server.

Log in through SSH

Using Terminal (Mac, Linux)

  1. Open Terminal
  2. Run this command to log into your server via SSH:
    ssh [email protected]
  3. If you receive a message about the authenticity of the host, type yes to continue connecting.
  4. Enter the root password for your server when prompted.

Using PuTTY (Windows)

You must have a compatible SSH client, such as PuTTY, to make an SSH connection on Windows. You can download PuTTY from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html.

  1. Open PuTTY
  2. Enter your domain or IP address as the hostname.
  3. Input 22 for the port number.
  4. Ensure that the Protocol is set to SSH.
  5. Select the Open button.
  6. If you receive a message about the authenticity of the host, type yes to continue connecting.
  7. When prompted for the username, type root.
  8. When prompted for the password, enter the root user's password.

    It's normal not to see anything change on the screen as you enter your password.

Clearing the Queue

When logged into SSH with root access, you will need to run a few commands to clear the queued mail files and the mail database.

Stopping the Mail System

It's a good idea to stop the mail system before clearing out the queue, as it will take the mail system offline while you clean it up. Enter the following command to stop the mail service:

service exim stop

Stop Exim to Clear Mail Queue

Clearing out the Files

Once exim has stopped, use the following command to clear out the mail files:

exim -bp | awk '{print $3}' | xargs exim -Mrm - removing *

This command might take a while to complete if you have a large queue. You will not be provided any progress indicator, but you will see a list of the messages as they are being removed. You will know it's completed when the command prompt returns.

Clearing out the Database

  1. Stop the tailwatchd service by running this command:

    /scripts/restartsrv_tailwatchd --stop
  2. Then, stop the eximstats by running the command:

    /scripts/restartsrv_eximstats --stop
  3. Enter the following command to remove the mail stats database:

    find /var/cpanel -name 'eximstats_db*' -exec rm {} +

    Drop EximStats (clearing mail queue)

  4. Run this command to restart the eximstats and recreate the mail stats database:

    /scripts/restartsrv_eximstats

    Create EximStats

  5. Finally, enter this command:

    /scripts/restartsrv_tailwatchd --start

Clearing out the Log

Clearing out the log will reduce the file count, which may have increased as a result of the excessively large mail queue. This is essential because keeping your file count lower will help your server perform better.

  • Run the following command to clear out the log:

    rm -rf /var/spool/exim/msglog/*

Restart The Mail System

Run the following command to start the mail system again.

service exim restart

Start Exim

When the mail system starts, you will be finished clearing the queue.

Loading...