Clear qmail mail queue

Posted on 2007-04-03
Last Modified: 2013-12-02
I have a dedicated server running qmail.
I need know how to clear the email queue.

Question by:steelseth12
  • 2
  • 2

Expert Comment

ID: 18846281
You can also purge the queue by below commands:-
To start qmail
svc –u /service/qmail/
svc –u /service/smtpd/
To stop qmail
svc –d /service/qmail/
svc –d /service/smtpd/

Below is the handy info about qmail:=

Some important directories/ files are:
/var/qmail/bin                        :      contains the qmail binaries
/var/qmail/service/qmail/log/main      :      contain the qmail log files

/var/qmail/service/qmail/log/main/current : this file contains latest/ current information about the queue

Some important commands related to qmail are:
(WARNING: not all commands are supposed to be run by users)

•qmail-qstat gives a human-readable breakdown of the number of messages at various spots in the mail queue.
•qmail-qread scans the outgoing queue of messages. For each message it prints various human-readable information, including the date the message entered the queue, the number of bytes in the message, the message sender, and all the recipients still under consideration.

A few words about the queue pileup:
The qmail server is very efficient in mail relaying and delivery. However, it is dependent on some underlying services. For example: DNS server and Network connectivity. If either of them is not upto the mark, then qmail server will not be able to relay mails, leading to a queue pileup. Hence check the following things:
1.      Verify with the networking team if the network connectivity is OK.
2.      Verify with the networking team if the DNS is working fine.
(We’ve had many instances where the server receives many mails for a domain which is not having its MX record defined properly or is not defined. Get this rectified by the networking team or the DNS team and the queue should come down quickly. The commands to find out the messages to/from a given domain are given below.)

Following steps may be used to manage the queue pileup:

1.      Check the number of messages in the queue

2.      Get the number of mails relayed
grep -c accepted current ; grep -c new current
987      (Delivered mail)
577      (New mails, waiting to deliver)

3.      How to track the messages,  with the "TO Address" information
a> [root@e2ksmtp01 qmail]# grep '' *
@4000000040a534881db6e53c.s:@4000000040a532700521703c starting delivery 13653102: msg 1093445 to remote
current:@4000000040a539ee2fac086c starting delivery 13658719: msg 1096679 to remote
      b>      grep 13653102 *
@4000000040a534881db6e53c.s:@4000000040a532700521703c starting delivery 13653102: msg 1093445 to remote
@4000000040a534881db6e53c.s:@4000000040a5327014d6a5ec delivery 13653102: success:<>_Queued_mail_for_delivery/
      c>  grep 13658719 *
current:@4000000040a539ee2fac086c starting delivery 13658719: msg 1096679 to remote
current:@4000000040a539ef0e6280b4 delivery 13658719: success:<>_Queued_mail_for_delivery/


4.      To see the messages in the queue currently
tail –f current
While tailing this file, you will get some idea about the mails. Try to figure the domain to which maximum number of messages are destined. After getting this information, check if the MX record of that domain is configured properly. If not, get this into the nmotice of DNS team/Shift manager to get this corrected.

5.      To get the messages in the queue related to
root@e2ksmtp01 main]# qmail-qread |grep |more

6.      To get the number of messages in the queue related to
root@e2ksmtp01 main]# qmail-qread | grep | wc -l
8.  To see mails for only Run the below command
root@e2ksmtp01 main]# qmail-qread | grep -A1 | more
      3 Jun 2005 14:51:27 GMT  #1094294  5499  <>  remote
      2 Jun 2005 17:09:55 GMT  #1094202  2828  <> remote
      3 Jun 2005 12:22:45 GMT  #1094340  3225  <> remote
      3 Jun 2005 06:00:14 GMT  #1095237  3524  <> remote

7.      To get the number of un-delivered messages received on 30th or 2nd June March queue
root@e2ksmtp01 main]#qmail-qread |grep –c "30 Mar"
root@e2ksmtp01 main]#qmail-qread |grep –c "2 Jun"

8.      List the current messages in queue.
             a> root@e2ksmtp01:ls -lt
      total 2467300
-rw-r--r--    1 qmaill   nofiles     59487 Jun  3 10:54  [00mcurrent
-rwxr--r--    1 qmaill   nofiles    998008 Jun  3 10:54  [01;32m@4000000042a06f2c101587e4.s
-rwxr--r--    1 qmaill   nofiles    998079 Jun  3 10:51  [01;32m@4000000042a06e712382242c.s
-rwxr--r--    1 qmaill   nofiles    998087 Jun  3 10:48  [01;32m@4000000042a06dc708569714.s
-rwxr--r--    1 qmaill   nofiles    998158 Jun  3 10:45  [01;32m@4000000042a06d220e3de984.s
-rwxr--r--    1 qmaill   nofiles    998033 Jun  3 10:43  [01;32m@4000000042a06c8e28431b24.s

b> To read log file "@4000000042a06f2c101587e4.s" Run the below command.
      From here you can find if the mails are not getting relayed for a particular domain.
      Go to the folder /var/qmail/service/qmail/log/main
     [root@e2ksmtp01 main]# cat @4000000042a06f2c101587e4.s |more
      @4000000042a06e712847b2ec status: local 0/120 remote 78/120
@4000000042a06e712849f124 starting delivery 2111462: msg 1096015 to remote tsing
      @4000000042a06e71284a4714 status: local 0/120 remote 79/120
      @4000000042a06e7128c1ebfc delivery 2111458: failure: Sorry,_I_couldn'
      @4000000042a06e7128ca9e8c status: local 0/120 remote 78/120
      @4000000042a06e7129c69674 bounce msg 1093870 qp 18749
      @4000000042a06e7129c9c6dc end msg 1093870
      @4000000042a06e7129d51d34 new msg 1096106
      @4000000042a06e7129d7ccb4 info msg 1096106: bytes 2588 from <> qp 18749 uid 197
      @4000000042a06e712a60983c starting delivery 2111463: msg 1096106 to remote
5> Lets say if there are mails from a specific user which is not getting relayed or if someone is trying to relay: Run the
      below command to locate that message and open that message.
           a>  root@e2ksmtp01 main]# locate -u
b> root@e2ksmtp01 main]# locate -u 1094294
      c> root@e2ksmtp01 main]# vi /var/qmail/queue/mess/0/1094294
 [?1048h [?1047h [?1h = [1;24r [?25h [?25h [27m [m [H [2J [?25l [24;1H"/var/qmail/queue/mess/0/1095375" 72L, 3217C [1;1HReceived: (qmail 23499 invoked from network); 3 Jun 2005 12:22:52 -0000
      Received: from unknown (HELO (
       by 0 with SMTP; 3 Jun 2005 12:22:52 -0000
Received: from mail pickup service by with Microsoft S  [5;1HMTPSVC; [6;10HFri, 3 Jun 2005 08:22:52 -0400

      From: <>
      To: <>
Subject: GIS-CMC-Emergency < 2 Hrs -- Shutdown of frbora58, frbora59 and frbora6  [10;1H0 -- FRANCE / BELFORT -- Open --
      Date: Fri, 3 Jun 2005 08:22:52 -0400
      MIME-Version: 1.0
      Content-Type: multipart/alternative; [14;9Hboundary="----=_NextPart_000_3737_01C56815.6F5EC190"
      X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
      Message-ID: <>
      X-OriginalArrivalTime: 03 Jun 2005 12:22:52.0405 (UTC) FILETIME=[F68F8250:01C568  [18;1H36]

      This is a multi-part message in MIME format.

      Content-Type: text/plain; [1;1H [?25h

To do a nslookup type below command.
root@e2ksmtp01 main]# dig mx
[root@e2ksmtp01 main]# telnet 25
LVL 20

Author Comment

ID: 18850578
hello nishin
thanks for the reply dont know if this is of any relevance but the server is running on freeBSD and the directory structure s different , also i dont have the qmail-qstat, qmail-qread commands available.

Accepted Solution

nishin earned 500 total points
ID: 18858485
Sorry, i did realise its in FREEBSD, Ok below is the few commands

-Start qmail
# /usr/local/etc/rc.d/ start

-Check qmail and tcpserver are running
# ps -ax | grep tcpserver
# ps -ax | grep qmail

You can refer the below links to:
LVL 20

Author Comment

ID: 18859499
Thanks for all your help

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Nearly six years ago I was hired by a company to be their senior server engineer. One of my first projects was to implement Exchange Server 2007 on a Windows Server 2008 Single Copy Cluster for high availability. That was the easy part; read on to l…
This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In this video we show how to create an Accepted Domain in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Ac…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question