Mail Queue Management Exim

Main things we need while managing a Mail Queue is removing spam mails, Frozen mails, Bounce mails, Queue force rerun etc.

I am adding some commonly used commands below for managing Exim Servers

To get the total number of mails in the queue

# exim -bpc

To list the mails in the queue

# exim -bp

Used to remove the message from queue with Exim Id : 1VcjOL-0002YV-8g

# exim -Mrm 1VcjOL-0002YV-8g

Displays the Header details of the particualr email

# exim -Mvh 1VcjOL-0002YV-8g

Displays the body of the particular email

# exim -Mvb 1VcjOL-0002YV-8g

Re-run the Mailq

# exim -q -v

Re-run the mailq even if the server is experiencing Load

# exim -qf -v

Gives the Email Id’s of the mails in the queue

# exiqgrep -i

To deliver mails forcefully

# exim -qff

Gives the Mail Id’s of the mails send from email@domain.com

# exiqgrep -i -f email@domain.com

To remove mails from mail@domain.com

# exiqgrep -i -f mail@domain.com | xargs exim -Mrm

To remove the mails in the queue completely

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

Last day a server came for management and had more than 200K mails in that and we had to remove mails from a particular email account. In such cases you can use the below script

# exim -bpr | grep "mail@domain.com" | awk '{ print $3 }' > mailids.txt
# for i in `cat mailids.txt` ; do exim -Mrm $i ;done

To remove the frozen mails

# exim -bpr | grep frozen | awk {‘print $3'} | xargs exim -Mrm

Or

# exiqgrep -z -i | xargs exim -Mrm

Another useful command for removing all emails from queue matching specific patterns ( like email address , subject , etc )

#  exiqgrep -i  > /tmp/mailids ; for id in `cat  /tmp/mailids` ;do exim -Mvh $id  |  grep "pattern" && exim -Mrm $id;  done ;  rm -f /tmp/mailids
Facebook Comments