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:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 9 comments… read them below or add one }

1 Oldzhay 11.19.08 at 12:22 pm

Hello,
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
O/p:

213376

… and i afraid i cannot use this solution.

Regards
Ol.
Bulgaria

2 Oldzhay 11.19.08 at 12:32 pm

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.

router_mailxpire:

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

… you are welcome :)

Cheers

3 vivek 11.19.08 at 12:41 pm

Oldzhay,

Thanks for sharing your solution!

4 Dallas Marlow 11.19.08 at 1:04 pm

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.

5 vivek 11.19.08 at 1:08 pm

Dallas,

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

6 akbar 01.10.09 at 3:08 am

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

7 Gabriel M 02.04.09 at 2:09 am

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

8 Houssam Ballout 06.07.09 at 12:13 pm

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

9 Oldzhay 06.08.09 at 8:42 am

“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

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

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

Previous post: What is Big Iron UNIX Computer?

Next post: Update FreeBSD Using Proxy Server (csup / portsnap proxy update)