HomeHome : Help Center : Question

How do I delete thousands of e-mail messages with cPanel or Horde's webmail interface?

Answer: Important: cPanel now provides an easier way to manage large amounts of email. Visit the cPanel Email Disk Usage page for more information.

If you run a website, you may find out one day that you have a mail account containing thousands of messages — or possibly even hundreds of thousands. The most common reason this happens is because the default e-mail account is set up as a "catch-all" address. This will direct all e-mail sent to invalid usernames at your domain to the default Inbox. Because spammers send out spam messages to invalid e-mail addresses all the time, the number of e-mails received by the default mailbox can grow by thousands of messages each day.

The best solution to this problem is to prevent it. If you have a Web server that is running cPanel, you can turn off the "catch-all" address by selecting the "Default Address" panel within the Mail section of the cPanel interface. Then choose the option that says "Discard with error to sender (at SMTP time)." This will bounce all invalid e-mails back to the sender and will keep the messages from piling up in your default mailbox. Over time, this can help save a lot of hard disk space on your server.

Of course, if you're like me, you caught this problem after thousands of messages had already filled your default e-mail account's Inbox. In my case it was over 500,000 messages. I realized that deleting these messages one page at a time via the Horde webmail interface would take a while (as in several days). So I figured there must be some easier way to delete the messages. Fortunately, after doing some research, I found that there is indeed a simple way to remove all the messages in the Inbox.

Just follow these basic steps:

  1. Log into the Horde Mail system.
  2. Click the "Folders" icon at the top of the window.
  3. Check the box next to "Inbox" or the mailbox that contains the messages you want to delete.
  4. From the "Choose Action:" drop-down menu, select "Empty Folder(s)."
  5. You will be prompted to confirm the action, as it is not undoable.
  6. Click "Empty Selected Folders" to clean out the mailbox.

Depending on how many messages are stored in your Inbox, this operation may take a few seconds to several minutes to complete. The only catch is that if the mailbox contains too many messages, the operation will time out and will not empty the mailbox. This is what happened to me with my 500,000+ messages.

If this is also your situation, you may have to delete the message folders manually. To do this, you will first need to navigate to the mail folder, which is located in the following directory:

/home/username/mail/ (where "username" is the username for the mail account)

The two folders you'll need to delete are the cur and new folders, which contain the messages. You may be able to do this with an SSH or SFTP program, though I also had problems with this method timing out. If you know some basic Unix commands, you can use a terminal (command-line) program to manually delete the folders. First, navigate to the mail folder, then recursively delete the cur and new directories. The commands to do this are:

$ cd /home/username/mail
$ rm -rf cur
$ rm -rf new

Again, even this method may take a while if the directories are loaded with thousands of mail messages. But it should eventually remove the folders. This command-line method should only be used a last resort, as the maildirsize file will no longer contain the correct information for the mail account. Fortunately, as soon as a new message is received into the empty Inbox, the cur and new folders are automatically recreated and the maildirsize is updated with the correct data.

If you have been wondering how to delete a large number of messages stored on your mail sever, I hope this information is helpful and saves you a lot of time.

Published: November 9, 2008   —   Updated: May 23, 2019 — by Per Christensson

Answer from the PC Help Center