4

I use the following command to delete the exim mail queues

exiqgrep -i | xargs exim -Mrm

or

# following commands seems to work faster compared to the above.
exim -bpru | awk {'print $3'} | xargs exim -Mrm

But the above commands do not work when the mail queue size is more than 100,000. It get stuck. So, I am using the following script which works fine regardless of the number of mails in the queue.

My question is, will it delete correctly ?

/etc/init.d/exim stop;
sleep 10;
killall -9 exim eximd
sleep 5;

#clean out the mail queue
find /var/spool/exim -mindepth 2 -type f -exec rm -rfv {} \;

#clean out the mail db files
find /var/spool/exim/db -type f -exec rm -rvf {} \;

/etc/init.d/exim restart
Mani
  • 554
  • 6
  • 11
  • 26

4 Answers4

4

I believe you are looking for this...

service exim stop
rm -fvr /var/spool/exim/input
service exim restart

However a slightly more sane method is to remove the messages on a per user basis...

egrep -Rl "((`pwd | cut -d / -f3`|$(grep `pwd | cut -d / -f3` /etc/userdomains | cut -d : -f1 | tr '\n' '|' | sed 's/|$//g'))|/home/`pwd | cut -d / -f3`)|X-Failed-Recipients" /var/spool/exim/input --include='*-H' | awk -F "/" '{gsub("-[A-Z]$","");print$NF}' | xargs exim -Mrm 
rcjohnson
  • 899
  • 6
  • 12
1

I have had success with the following, even when there are millions of emails in queue.

for i in $(exim -bp | awk '{print $3}'); do exim -Mrm $i; done

  • Note that the question contains an explicit question, "My question is, will it delete correctly ?", about a piece of code. – Kusalananda Oct 11 '22 at 18:44
0

In addition, to delete the emails of a specific user:

grep -lr '[email protected]' /var/spool/exim/input/ | \
    sed -e 's/^.*\/\([a-zA-Z0-9-]*\)-[DH]$/\1/g' | \
    xargs exim -Mrm

exim -bp | \
    grep "user_email-account" | \
    awk '{print $3}' | \
    xargs exim -Mrm
exhuma
  • 222
  • 2
  • 13
A Yashpal
  • 91
  • 5
0

To remove all messages from the queue, enter:

# exim -bp | awk '/^ *[0-9]+[mhd]/{print "exim -Mrm " $3}' | bash
slm
  • 363,520
  • 117
  • 767
  • 871