Exim is a powerful mail transfer agent (MTA) used on many Linux servers. When emails can't be delivered immediately, they get put into a "queue." Managing this queue is crucial for server health and ensuring mail delivery. This guide provides quick commands for common Exim queue tasks.
CLEARING THE EXIM MAIL QUEUE
Sometimes, you need to clear out stuck or unwanted emails from the queue.
Remove All Mails: This command directly deletes all files from the input directory of the Exim spool, effectively clearing the entire queue.
rm -rf /var/spool/exim/input/*Delete All Frozen Mails: Frozen emails are those that Exim has temporarily stopped trying to deliver due to issues.
exim -bpr | grep frozen | awk {'print $3'} | xargs exim -MrmAlternatively, a more concise command:exiqgrep -z -i | xargs exim -MrmDelete Frozen Mails Older Than a Day: This is useful for clearing old, stalled messages without affecting newer ones. The
86400represents seconds (1 day).exiqgrep -zi -o 86400 | xargs exim -MrmYou can change86400to any number of seconds for a different time frame.Clear Spam Mails: If your logs indicate messages are marked as
[SPAM].grep -R -l [SPAM] /var/spool/exim/msglog/*|cut -b26-|xargs exim -MrmClear Frozen Mails (Based on Log Entry):
grep -R -l '*** Frozen' /var/spool/exim/msglog/*|cut -b26-|xargs exim -MrmClear Mails for Unverified Recipients:
grep -R -l 'The recipient cannot be verified' /var/spool/exim/msglog/*|cut -b26-|xargs exim -MrmRemove Mails from a Specific Sender (e.g., 'root'): Replace
""with the sender's email address or username, for example,root@yourhostname.exim -bp |grep ""|awk '{print $3}'|xargs exim -MrmRemove 'nobody' Mails: These often come from scripts. Replace
HOSTNAMEwith your server's hostname.From a specific sender (
nobody@HOSTNAME):exiqgrep -i -f nobody@HOSTNAME | xargs exim -MrmFor a specific recipient/domain (
nobody@HOSTNAME):exiqgrep -i -r nobody@HOSTNAME | xargs exim -Mrm
Delete Mails for a Specific Domain: Replace
yourdomain.comwith the actual domain.exim -bp | grep "yourdomain.com" | awk {'print $3'} | xargs exim -Mrm
DELIVERING MAILS FROM THE QUEUE
If emails are stuck but should be delivered, you can force a delivery attempt.
Force Deliver All Mails: This command attempts to deliver all messages in the queue. The
-P 40option attempts 40 deliveries in parallel.exim -bpru |awk '{print $3}' | xargs -n 1 -P 40 exim -v -MFlush the Mail Queue (Force Another Run): This tells Exim to process the queue again.
exim -qffAlternatively:/usr/sbin/exim -qffexim -qfForce Deliver Mails of a Particular Domain: Replace
domain.comwith the target domain.exim -v -Rff domain.comForce Deliver a Specific Message: Replace
MSGIDwith the message's unique ID.exim -M MSGIDTo view the transaction during delivery:exim -v -M MSGID
CHECKING THE EXIM MAIL QUEUE STATUS
These commands help you monitor the queue and inspect individual messages.
Exim Queue Summary: Provides details like count, volume, oldest, newest message, and domain breakdown.
exim -bp | exiqsummNumber of Frozen Mails:
exim -bpr | grep frozen | wc -lTotal Number of Mails in Queue:
exim -bpr | grep "<" | wc -lA simpler alternative:exim -bpcView Mail in Queue for a User/Sender: Replace
$namewith the username or email address.exim -bp|grep $nameCheck All Mails in the Queue: This lists all messages and their IDs.
exim -bpView Log for a Message: Replace
message IDwith the actual ID.exim -Mvl message IDView Message Header: Replace
$MSGIDwith the message ID.exim -Mvh $MSGIDView Message Body: Replace
$MSGIDwith the message ID.exim -Mvb $MSGID
ADVANCED EXIM TOOLS
Simulate SMTP Transaction: This command helps debug Exim's checks, ACLs (Access Control Lists), and filters without actually sending a mail. Replace
127.0.0.1with the IP you want to simulate from.exim -bh 127.0.0.1Most Used Mailing Script Locations: This can help identify scripts sending a lot of mail.
grep cwd /var/log/exim_mainlog | grep -v /var/spool | awk -F"cwd=" '{print $2}' | awk '{print $1}' | sort | uniq -c | sort -nCheck Syntactic Errors in Configuration: Use this when modifying Exim's configuration file.
exim -C /config/file.new -bV