facebook youtube pinterest twitter reddit whatsapp instagram

How to Delete Mail Queue in Postfix

I had some issue with one of mailserver, where postfix keeps retrying to send mail to a mistyped email address, it was very frustrating considering this particular email was holding back thousands of email, this how I solved it:

To delete a mail queue in Postfix, you use the postsupercommand, which is used for postfix mail queue related stuff, note that it can only be run by superuser of the system.

Before you delete a mail in the queue, you'll want to check if there is any mail in the queue at all, you can check by using the mailqcommand, for example, I was trying to send a mail to multiple users, and let's assume it's not going through, you are gonna see something that looks similar as below:

-Queue ID-  --Size-- ----Arrival Time---- -Sender/Recipient-------
7483D5CB40*     851 Thu Jul 16 11:53:40  user@gmail.com
                                         user@gmail.com
                                         user@yahoo.com

-- 0 Kbytes in 1 Request.

Note: The reason why I have multiple 'Sender/Recipient' above is that I am sending a single mail to multiple addresses, just the way you can add multiple emails when sending in an email client, e.g Gmail.

Now, to remove a mail queue, you note the -Queue ID-, and you then use the following command:

postsuper -d Mail_Queue_ID

Remove All Mails from Queue

This is where you would have multiple mails with different user, for illustration purpose, see below example:

-Queue ID-  --Size-- ----Arrival Time---- -Sender/Recipient-------
7483D5CB40*     851 Thu Jul 16 11:53:40  user@gmail.com
                                         user@gmail.com
                                         user@yahoo.com

9483E5CB40      851 Thu Jul 16 11:53:40  anotheruser@gmail.com

4483W5CB40      851 Thu Jul 16 11:53:40  bob@gmail.com

-- 0 Kbytes in 1 Request.

You can see the above all have a different Queue ID, to clear them all, you use the following command:

postsuper -d ALL

Remove only All Deferred Mails In Queue

If you notice at the start of this guide I said, I had issue with some invalid recipient address, here is the deal:

The differed mail queue holds all messages or mails that have soft-failed (temporary failure), and need to be retried, in most case the failure can be due to invalid recipient address, or greylisting by spam filters.

If you want to delete only the differed mail queue, you use the following command:

postsuper -d ALL deferred

Enjoy.

Related Post(s)

  • Setting Up Send-Only Mail Server From Scratch (With Haraka)

    In this guide, I would walk you through the steps of setting up an email server that can be used as a send-only mail server, we would not be dealing with receiving mails, we only care about sending em

  • Send Mail with Attachment Using Mutt in GNU/Linux

    Mutt is a powerful text-based mail client for Unix/Linux operating systems. It features color support, message threading, MIME support...

  • How To Send Mail To Multiple Addresses Using (mailx)

    In this guide, you'll learn a couple of ways you can send mail to multiple addresses using mailx. mailx is a utility program for sending and receiving mail. I assume you already have mailx command, i