Exim Mail Server Tips

We can use the below mentioned commands to manage mails in Exim mail queue.

List the messages in the queue

exim -bp

List the messages with the count in the queue

exim -bpc

Grep messages from the mail queue.

grep mail@mail.com /var/log/exim_mainlog

tail -f  /var/log/exim_mainlog | grep mail@mail.com

Ex:  # grep 1IapG1-0007YX-8t  /var/log/exim_mainlog

Ex : # grep mail@mail.com /var/log/exim_mainlog

Grep a particular mail

tail -f /var/log/exim_mainlog | exigrep mail_name

Forcibly deliver the mails

exim -qff -v

Run Mail queue.

runq -qqff&

Find if there is any mails are generated from the /home directory.

tail -f /var/log/exim_mainlog | grep “cwd=/home”

Use following two scripts to catch the spammer.

exim -bpr | grep “<*@*>” | awk ‘{print $4}’|grep -v “<>” | sort | uniq -c | sort -n

That will show you the maximum no of email currently in the mail queue have from or to the email address in the mail queue with exact figure.

exim -bpr | grep “<*@*>” | awk ‘{print $4}’|grep -v “<>” |awk -F “@” ‘{ print $2}’ | sort | uniq -c | sort -n

That will show you the maximum number of emails currently in the mail queue have for the domain or from the domain with number.

To delete the mails of a particular mail user.

exiqgrep -ir sysadmin@admindiary.com | xargs exim -Mrm

or

exiqgrep -i -t user@domain.com | xargs exim -Mrm

Delete Mail by a Domain

for i in `exiqgrep -i -f domain.com`; do exim -Mrm $i; done

Delete Mail for a Domain

for i in `exiqgrep -i -r domain.com`; do exim -Mrm $i; done

To remove mails older than 1 day from the mail queue.

exiqgrep -o 86400 -i | xargs exim -Mrm

Removes Mail Older than 3 Days

for i in `exiqgrep -i -o 259200`; do exim -Mrm $i; done

To remove the mails older than 2 days from the mail queue using the cron

* 3 * * * for i in `exiqgrep -i -o 172800`; do exim -Mrm $i; done >/dev/null 2>&1

Removing Nobody Mail

for i in `exiqgrep -i -f nobody`; do exim -Mrm $i; done

Removing Mails with Weird Characters

for i in `exiqgrep -i -f “^<>$”`; do exim -Mrm $i; done

To remove a message from the queue

exim -Mrm {message-id}

To remove the SPAM tagged mails from the exim mail queue.

grep -R -l [SPAM] /var/spool/exim/msglog/*|cut -b26-|xargs exim -Mrm

To delete frozen mails

exim -bp | grep frozen | awk ‘{print $3}’ | xargs exim -Mrm
grep -R -l ‘*** Frozen’ /var/spool/exim/msglog/*|cut -b26-|xargs exim -Mrm

To find the frozen mails

exim -bp | grep frozen | awk ‘{print $3}’

To remove bounce back and recipient cannot be verified mails from the mail queue.

grep -R -l ‘The recipient cannot be verified’ /var/spool/exim/msglog/*|cut -b26-|xargs exim -Mrm

To remove all messages from the queue

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

or

for i in `exiqgrep -i -f `; do exim -Mrm $i; done

Alternate Method for removing all mails.

exim -bp | exiqgrep -i | xargs exim -Mrm

To send mail

mail -v mail@mail.com

Exim restart

/sbin/service exim restart
/etc/init.d/exim restart

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.