I use the following command to delete the exim mail queues

exiqgrep -i | xargs exim -Mrm


# 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

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 

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

grep -lr 'user@domain.com' /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

To remove all messages from the queue, enter:

# exim -bp | awk '/^ *[0-9]+[mhd]/{print "exim -Mrm " $3}' | bash

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.