Sendmail: Clear / Delete / Flush Mail Queue

by on July 1, 2011 · 10 comments· LAST UPDATED July 1, 2011


How can I permanently delete all e-mail messages in the Sendmail mail server (SMTP) queue using UNIX / Linux command prompt?

You can use the mailq command sendmail -bp command to display a summary of the mail messages queued for future delivery. Type the following command:
# mailq
# sendmail -bp
Sample outputs:

		/var/spool/mqueue (1 request)
-----Q-ID----- --Size-- -----Q-Time----- ------------Sender/Recipient-----------
p61J75u5037681      893 Fri Jul  1 14:07 
      8BITMIME   (Deferred: Connection timed out with
		Total requests: 1

You can cd to /var/spool/mqueue and delete all files if you want to get rid of all messages in the queue:
# cd /var/spool/mqueue/
# ls
# rm * Tool

Sendmail mail server does not provide any command to remove messages from the mail queue. The above will delete all messages from the mail queue. You can use script located in sendmail source code contrib directory as follows:
# mailq
Sample outputs:

		/var/spool/mqueue (1 request)
-----Q-ID----- --Size-- -----Q-Time----- ------------Sender/Recipient-----------
p61J75u5037681      893 Fri Jul  1 14:07 
      8BITMIME   (Deferred: Connection timed out with
		Total requests: 1

Note down Q-ID p61J75u5037681 and run as follows:
# ./ -C /etc/mail/ -d /var/spool/mqueue/p61J75u5037681

  • -C /etc/mail/ - Specify sendmail config file.
  • -d /var/spool/mqueue/p61J75u5037681 - Delete the messages specified by source. In this case by Q-ID.

To delete all messages queued for the domain. First, you need to set QIDS either using the mailq command or manually as follows:

QIDS="qid1 qid2 qidN"


QIDS="$(mailq | grep -B1 '' | grep '^[a-z]'  | awk  '{print $1}' | sed  's/\*$//')"

Use the following bash for loop to delete all messages for

for q in $QIDS
  /usr/local/bin/ -C /etc/mail/ -d /var/spool/mqueue/$q

More links and information:

Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?

{ 10 comments… read them below or add one }

1 praveen July 12, 2011 at 11:36 am

Interviewer asked me one question:
User is unable to send/receive the mail.
How u will troubleshoot it?
Explain in clear manner with steps.
I didnt answer to this question.
Can u plz tell the answer to this question as soon as poss


2 Yogesh July 12, 2011 at 12:11 pm

Hello Praveen,

Your query is not answerable in one line. It requires a series of test to be performed before reaching to any conclusion.

User is unable to send/receive the mail –> Is he using mail client or web interface?
What is the error in mail client or web interface?
Is it only delay in mail or proper error mesg like 5.5.1?
Do you see any mail queue or bounce back mails?
Is your mail server blacklisted?
Is the problem while sending / receiving mails from a particular domain say

To troubleshoot –> depends on Question 1

Explain in clear manner with steps –> Not possible, until you are a mail server genius :-)


3 praveen July 12, 2011 at 2:59 pm

user is using mail client. but he is unable to send/receive the mail. at server this user is added. what might be the problem. When he assiging the port of 25. it is automatically taking 25 as 543 port. And prompting the username already exits.
What to do?


4 Yogesh July 12, 2011 at 3:50 pm

Try telnet 25
This is to test firewall at client’s end
Next, observe the error mesg thrown by mail client. It helps alot.
I suppose you mistyped port 587. Both port 25 and 587 are used for outgoing SMTP. In most cases ISPs block port 25, so clients are advised to configure mail client program to point to port 587.
The sending action will ask for username / password if the check box ‘My outgoing server requires authentication’ is selected. Use ‘Use same settings as my incoming server’ to avoid this prompt.


5 amrik September 11, 2012 at 2:18 pm

In Ubuntu, the path for mail was /var/spool/mail. On deleting the files in this folder, mailq still listed some pending mails.
On some digging I found some deferred mails sitting in the /var/spool/postfix/defer and /var/spool/postfix/deferred folders. I deleted these files and my mailq is now empty.


6 Rajgopal H.G. April 2, 2013 at 7:00 am

@amrik : For postfix servers, “postsuper” is the powerful command to monitor.
Example to delete all the pending ques (Delete the ques ONLY when you are sure):
# postsuper -d ALL


7 David Ramirez May 23, 2013 at 7:37 pm

Worked like charm – even the last set of instructions pertaining to feeding the QIDS was appropriate, as some failing command flooded the queue with mails to “”. I installed the script and… bye bye bad messages.


8 Daniel Moreno July 2, 2013 at 12:40 pm

In another web site (No remember) I see to flush sendmail queue:

sendmail -q -v


9 amir August 11, 2013 at 1:40 pm

find /var/spool/mqueue/* -type f -exec grep -irl “” {} \; -exec rm -vf {} \;


10 kishan July 14, 2014 at 4:20 am

in linux mail server there is 7 mails in queue ..why get stuck mails in queues in server why not in client mail app..if there is mail id problem..what will happen if i remove queue mails form server..


Leave a Comment

Tagged as: , , , , , , , , , , , , ,

Previous Faq:

Next Faq: