Sendmail: Clear / Delete / Flush Mail Queue

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:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 10 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
10 comments… add one
  • praveen Jul 12, 2011 @ 11:36

    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

    • Yogesh Jul 12, 2011 @ 12:11

      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 :-)

  • praveen Jul 12, 2011 @ 14:59

    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?

    • Yogesh Jul 12, 2011 @ 15:50

      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.

  • amrik Sep 11, 2012 @ 14:18

    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.

    • Rajgopal H.G. Apr 2, 2013 @ 7:00

      @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

  • David Ramirez May 23, 2013 @ 19:37

    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.

  • Daniel Moreno Jul 2, 2013 @ 12:40

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

    sendmail -q -v

  • amir Aug 11, 2013 @ 13:40

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

  • kishan Jul 14, 2014 @ 4:20

    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 Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum