Exim Mail Queue

Posted by Ameya on October 18th, 2007 filed in Tips & Trix, exim4, linux, spam

Like thousands of others Email Server Administrator problem, our Exim mail server was targeted by spammers. I found that there was approximately 10000 emails residing in my mail queue. The exact number of emails in the queue were known by running :
exim -bpc

It was a tough job to clean up the queue. I tried the “exiqgrep” command to clean the emails those were older than 1 day from the queue.

exiqgrep -o 86400 -i | xargs exim -Mrm

Where 86400 are the seconds of 1 day.

However the above command was not of much help instead it keep on giving me errors. I had to think calmly to delete all the spams. I first decided ran the below command to Run additional queues in the background.

exim -qff &

I given this command multiple times. So that many queues were running at the same time. The next step was to clear all the Frozen messages from the mail queue.

exim -bpr | grep frozen | awk {’print $3′} | xargs exim -Mrm

Clearing the Frozen messages was a wise decision as it the mail queue was showing now 4000 messages in it. The other job was to find similar messages. I checked the queue again.

exim -bpr |more

I could guess that most of the emails are 2 or 3 days older. To clear all these spams the next command was helpful, which checked the mail queue then searched “2d” in it and taking the 3 argument which is Message Id… it deleted all those emails.

exim -bpr | grep 2d | awk {’print $3′} | xargs exim -Mrm

The queue was under my control after clearing the email older to two and three days. Still there were couple of hundreds emails in the queue. I noticed that there are many emails without a sender residing in the queue. It was very simple to clean these spams now.

exim -bpr | grep <> | awk {’print $3′} | xargs exim -Mrm

Yippie… I cleared the mail queue.

Some other useful Exim Queue managing commands are below :

exim -Mvh msgid View message header
exim -Mvb msgid View message body
exim -M msgid Force delivery of message
exim -v -M msgid View the transact of message

Force another queue run
exim -qf

Force another queue run and attempt to flush the frozen message
exim -qff

View the log for the message
exim -Mvl msgid

Remove message without sending any error message
exim -Mrm messageID

Giveup and fail message to bounce the message to the Sender
exim -Mg messageID

How much mail in the queue?
exim -bpc

How many Frozen mails in the queue
exim -bpr | grep frozen | wc -l

Deleteing Frozen Messages
exim -bpr | grep frozen | awk {’print $3′} | xargs exim -Mrm

To force exim update:
/scripts/eximup –force


5 Responses to “Exim Mail Queue”

  1. Serkan Hamarat Says:

    awk {’print $3′} should be:
    awk ‘{print $3}’

    please consider this.

  2. Ameya Says:

    Thanks for your suggestion Serkan. I re-tested this command with both arguments & it gives same output. Lol.
    Is the command I’ve mentioned giving you any error message? Which OS are you using?
    Your correction is definitely valid though. :)

  3. alex howe Says:

    I’m using debian sarge.

    For some reason when I issue the command

    exim -bpr | grep | awk {’print $3′} | xargs exim -Mrm

    I get the error

    -bash: syntax error near unexpected token `|’

  4. Nilkanth Says:

    Alex,

    Please note the single quotes.
    It might be the html treating it as punctuation.

    exim -bpr | grep | awk {’print $3′} | xargs exim -Mrm

    The line in curly braces should be
    {single-quote print $3 single-quote}

    Regards,
    Nilkanth

  5. stratosg Says:

    thx man! i wanted to clear up my mail queue and had no idea how. i used exiqgrep -o 86400 -i | xargs exim -Mrm with time 0 ;) thx again!

Leave a Comment

Free Domains Hosting at .co.nr Creative Commons License
This work by Ameya Pandit is licensed under a Creative Commons Attribution 2.5 India License
Photo Album