Exim Remove All messages From the Mail Queue

Question: I’m using Exim mail server under CentOS Linux. How do I remove all messages from the Exim mail queue using a shell prompt?

Answer: Exim is a mail transfer agent (MTA) used on Unix-like operating systems. It aims to be a general and flexible mailer with extensive facilities for checking incoming e-mail.

To print a list of the messages in the queue, enter:

# exim -bp

To remove a message from the queue, enter:

# exim -Mrm {message-id}

To remove all messages from the queue, enter:

# exim -bp | awk '/^ *[0-9]+[mhd]/{print "exim -Mrm " $3}' | bash
Dallas Marlow, suggested following clean command:
# exim -bp | exiqgrep -i | xargs exim -Mrm

Further readings:

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

🐧 42 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
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 jobs killall kill pidof pstree pwdx time
Searchinggrep 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
42 comments… add one
  • Oldzhay Nov 19, 2008 @ 12:22

    the most secure thing (and the most ugly one) you can do is delete all files from EXIM input folder (/var/spool/exim/input). The folder that uses exim to keep the mail queue .

    EXIM creates 2 files for email – 1 for the headers part and another for the message body. Erasing everything from this folder must erase the queue.

    EXIM names the files with the msg_id an put -H or -D part on the end of filename – H for headers an -D for body file

    -rw-r-----  1 exim exim 17961 nov 19 12:12 1L2kyk-0007gm-0v-D
    -rw-r-----  1 exim exim  1172 nov 19 12:12 1L2kyk-0007gm-0v-H

    The solution of Vivek is good, but for less traffic, otherwise if you manage lots of emails I recommend you to rm the files.

    One of my cases:
    [root@mta1 ~]# exim -bpc


    … and i afraid i cannot use this solution.


  • Oldzhay Nov 19, 2008 @ 12:32

    Another solution is put this router in the EXIM configure and run some queue runners – exim -qff&

    If you place the router in first place he will delete all messages older than X seconds. 1800 = 30 min.


     driver = redirect
     condition = ${if >= {$message_age}{1800}}
     data = /dev/null
     file_transport = address_file

    … you are welcome :)


  • 🐧 nixCraft Nov 19, 2008 @ 12:41


    Thanks for sharing your solution!

  • Dallas Marlow Nov 19, 2008 @ 13:04

    this is a much cleaner/safer way to do the same thing (using the tools provided by all modern exim installations)

    exim -bp | exiqgrep -i | xargs exim -Mrm

    exim -bp # this prints the contents of the mail queue
    exiqgrep # extracts the id from each mail
    xargs exim -Mrm # removes the mail

    exiqgrep is pretty flexible (for instance if you wanted to only extract the frozen email id’s used exiqgrep -iz ), exipick is an extension of exiqgrep that can help a bit too.

    • Roman Oct 27, 2014 @ 15:45

      I think it is enought to use

      exiqgrep -i | xargs exim -Mrm

      As the manual says, “it invokes exim -bpu itself and does not need to be invoked in a pipe”

    • Tozz Jul 15, 2015 @ 14:02

      Your solution is a lot slower with large queues. I had a few hundreds of thousands of messages, and using exiqgrep very little happened, but exiqgrep had its memory go through the roof.

      The prior solution (“exim -bp | awk ‘/^ *[0-9]+[mhd]/{print “exim -Mrm ” $3}’ | bash”) is much faster.

  • 🐧 nixCraft Nov 19, 2008 @ 13:08


    The faq has been updated with your command. Thanks for sharing with us!

    • Wendy Oct 9, 2015 @ 2:19

      The method very slow for > 100K emails, nothing happen after 60 seconds. The fastest way is using: exim -bp | awk ‘/^ *[0-9]+[mhd]/{print “exim -Mrm ” $3}’ | bash

  • akbar Jan 10, 2009 @ 3:08

    Have you been remove about 1200821 queue ?
    it wont work with “exim -bp | exiqgrep -i | xargs exim -Mrm” ( I tried to wait until 24hours, it get my swap until 0 free)
    so it must use script to remove the queue, in my case:
    -list all directory in ‘input’ folder:
    cd /var/spool/exim/input ; ls >> /tmp/folder
    -create a script name “removeall”
    echo “for b in `ls` ; do rm -f $b ; done” >> /tmp/removeall ; chmod 700 /tmp/removeall
    – go to input folder and exec command
    for a in `cat /tmp/folder` ; do cd $a ; /tmp/removeall ; cd .. ; done

    and it work great :)

    • adib ramezany Oct 21, 2013 @ 16:46

      fastest solution to remove all emails in exim queue (less than 5sec) :
      do these commands :

      cd /var/spool
      mv exim exim.old
      mkdir -p exim/input
      mkdir -p exim/msglog
      mkdir -p exim/db
      chown -R mail:mail exim
      /sbin/service exim restart

      enjoy it !!

      • Doeke Nov 15, 2013 @ 12:29

        You just saved my life! thanks!

      • Melvin Feb 5, 2014 @ 2:49


      • Benjamin May 12, 2014 @ 22:52

        You saved my life 2.
        You saved my life 3. 4. 5.

        I didn’t have ANY space for even making new dir. I just removed the input and anything inside and made a new input.


        • Adib Ramezany May 13, 2014 @ 15:22

          you are welcome…

      • Wendy Oct 9, 2015 @ 2:25

        If you have AV/AntiSpam:

        cd /var/spool
        mv exim exim.old
        mkdir -p exim/db
        mkdir -p exim/input
        mkdir -p exim/msglog
        mkdir -p exim/scan
        chown -R mail:mail exim
        /sbin/service exim restart

  • Gabriel M Feb 4, 2009 @ 2:09

    Thanks Oldzhay for you router to delete messages older than x seconds, I will definately test & apply in my setup.

  • Houssam Ballout Jun 7, 2009 @ 12:13

    Well, I remove all the messages in the queue but still am not able to send any mail :(

  • Oldzhay Jun 8, 2009 @ 8:42

    “Well, I remove all the messages in the queue but still am not able to send any mail”
    …this is another problem. Can you post some log here pls, and we can look for a solution

  • Tyler Aug 15, 2009 @ 7:52


    Your function can be simplified as:
    for dir in /var/spool/exim/input/*; do cd $dir; ls | xargs rm -f; done

    Of course, if your intention is to simply remove all files (not directories) underneath /var/spool/exim/input, that process can be simplified as follows:

    find /var/spool/exim/input -type f -exec rm -f {} +

    Of course, this assumes that there are no files below input that shouldn’t be deleted.

    • loser Feb 17, 2014 @ 19:32

      hahaha how bout leave the programming to the real men. Take your pathetic code somewhere else.

  • Prashant Naik Aug 29, 2009 @ 14:42

    To check the no. of mails in the queue use the command
    exim -bpc

    To check the list of pending mails use
    exim -bp

    To deliver the mails use
    exim -qf -d

    If working on a Server then check the load on it (using the command w ) and if the load is not high (less than 1.o) then you could also set 1 or 2 mail runners (do not set more than 2 as the load on the server may increase) using the command
    exim -qf &

  • J. Ruiz Apr 7, 2010 @ 13:57


    About the Dallas Marlow comment:

    It’s possible to do it without the “exim -bp” command.

    The command “exiqgrep -i | xargs exim -Mrm” does exactly the same, because exiqgrep looks up the queue by itself.


    J. Ruiz

  • bony Oct 7, 2010 @ 3:48

    i want to remove 4000 messages

  • Reikor Apr 22, 2011 @ 7:03

    I client of my have been hacked and they sent about 40 millions of mails.
    I have all of them in the input folder, i cant ls, du or nothing, this is a sh*t.
    Anyone have some script that do this really fast ? i dont want to wait 1 month for clean up.

  • rossixx May 23, 2011 @ 11:07

    here is a good solution:

    exim -bpru|awk {‘print $3’}|xargs exim -Mrm

  • Luis Santana Aug 25, 2011 @ 23:36

    Another command which can be used for this is the following

    exim -bp |awk {‘print $3’} |xargs exim -Mrm

  • Eric Gillette Oct 22, 2011 @ 0:28


    Thanks for your post — I saw what Akbar was trying to accomplish, but was wondering if there was a simpler way to do, and then I read down further to your post.

    I had a client who had over 300,000 messages in the Exim Queue after his server was compromised by a PHP script and using exiqgrep didn’t seem to work (since I imagine exiqgrep doesn’t expect to encounter that many messages in Exim’s queue in the first place).

    I created a shell command out of your command there, and ran it, and voila — everything is back to normal.

    In addition, I think it may be of note to mention that configserver.com makes two applications that are free for WHM called CMM (Mail Manager) and CMQ (Mail Queue Manager) which help with these kinds of issues, but of course if you have a massive queue (300,000 messages for example) they won’t really help much, since they also use Exim’s built-in toolset to run the commands.

    Thanks again Tyler! =0)

  • Thiwanka Nov 24, 2011 @ 13:34

    Thanks Tyler. It works.!

  • swapz Feb 15, 2012 @ 15:42

    Hi all,

    Not working for me :(
    I am new to linux

    and while executing

    for dir in /var/spool/exim/input/*; do cd $dir; ls | xargs rm -f; done


    find /var/spool/exim/input -type f -exec rm -f {} +

    It’s showing read only file system can not removed…

    plz let me know what I am missing …

    Thanks to all…. :)

  • Mahbubur Jul 10, 2012 @ 20:41

    This works as well which is much simplier:

    exiqgrep -i | xargs exim -Mrm


    # exim -bp
    9h 2.2K 1SoYFB-00082u-Lk *** frozen ***
    9h 2.2K 1SoYFB-00082z-OB *** frozen ***
    9h 2.2K 1SoYFB-000834-Qv *** frozen ***
    9h 53K 1SoYFB-000839-TW *** frozen ***

    # exiqgrep -i | xargs exim -Mrm
    Message 1SoYFB-000834-Qv has been removed
    Message 1SoYFB-00082u-Lk has been removed
    Message 1SoYFB-000839-TW has been removed
    Message 1SoYFB-00082z-OB has been removed

  • Karthik Jul 9, 2013 @ 21:19

    Can any one help me to use this exim mail queue delete command in cronjob

    exim -bp | awk ‘/^ *[0-9]+[mhd]/{print “exim -Mrm ” $3}’ | bash

    exim -bp | exiqgrep -i | xargs exim -Mrm

    either of these commands in cron job

    I run a cpanel server.

  • Drew Jul 26, 2013 @ 1:08

    Can you use just:
    exiqgrep -i | xargs exim -Mrm

    To remove all emails from the queue? Is exim -bp needed?

  • Poorya Dec 17, 2013 @ 7:26

    Can you guys guide me to how write a cronjob to remove any email in queue which was in the queue for more than 1 hour.
    I’m not sure if I should to put the script in the crontab or rounter field in exim configuration ?

  • Amir Feb 1, 2014 @ 17:01

    Hi I am a newbie here. I have got more than 400K emails in queue. Can anyone help me to delete them at once.


  • Poorya Feb 5, 2014 @ 6:11

    Login to your server as root from ssh and run the bellow command and wait for queue to get empty :

    exim -bp | awk ‘/^ *[0-9]+[mhd]/{print “exim -Mrm ” $3}’ | bash

    • Amir Feb 17, 2014 @ 20:11

      Thanks man, but this is the same mentioned in the article. However I tried but it is a huge queue.
      More than 1600000 emails are in queue. Is there any other way to delete the folder or something similar.

  • Martin Aug 17, 2014 @ 16:35

    Thanks! Worked for me… :-)

  • Oldzhay Sep 8, 2014 @ 18:31

    I shared one of my best solutions about… 6 years ago. It still works very well.

    If you only want to delete the entire queue, just put the following router at the beginning of exims routers section (after “begin routers”). You must cut all new input traffic because you will delete it as well.

    driver = redirect
    data = /dev/null
    file_transport = address_file

    After changing exim´s config, restart the daemon and fire “exim -qff&” several times. It will launch several parallel queue runners and will process all the queue in about 5 o 10 minutes.

    Hope that helps

  • Matheus Baldasso Feb 11, 2015 @ 12:04

    Simple snippet for remove all queue messages:

    exim4 -Mrm *

  • Ashif Zubair Jun 9, 2016 @ 7:54

    Thanks ,
    exim -bp | awk ‘/^ *[0-9]+[mhd]/{print “exim -Mrm ” $3}’ | bash
    helped me to remove 10XXXX mails from queue.

  • Fins Oct 12, 2016 @ 10:04

    Is there a way to just remove emails from the queue that are sent from one user i.e. john@example.com or remove emails that are sent from a single domain?

  • Shiloh Sep 28, 2017 @ 12:12

    Thanks a lot! This saves the day!

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