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 -Mrm
- Delete 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 change- 86400to 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 -Mrm
- Clear Frozen Mails (Based on Log Entry): - grep -R -l '*** Frozen' /var/spool/exim/msglog/*|cut -b26-|xargs exim -Mrm
- Clear Mails for Unverified Recipients: - grep -R -l 'The recipient cannot be verified' /var/spool/exim/msglog/*|cut -b26-|xargs exim -Mrm
- Remove 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 -Mrm
- Remove '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 -Mrm
- For 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 -M
- Flush the Mail Queue (Force Another Run): This tells Exim to process the queue again. - exim -qffAlternatively:- /usr/sbin/exim -qff- exim -qf
- Force Deliver Mails of a Particular Domain: Replace - domain.comwith the target domain.- exim -v -Rff domain.com
- Force 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 | exiqsumm
- Number of Frozen Mails: - exim -bpr | grep frozen | wc -l
- Total Number of Mails in Queue: - exim -bpr | grep "<" | wc -lA simpler alternative:- exim -bpc
- View Mail in Queue for a User/Sender: Replace - $namewith the username or email address.- exim -bp|grep $name
- Check All Mails in the Queue: This lists all messages and their IDs. - exim -bp
- View Log for a Message: Replace - message IDwith the actual ID.- exim -Mvl message ID
- View Message Header: Replace - $MSGIDwith the message ID.- exim -Mvh $MSGID
- View 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.1
- Most 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 -n
- Check Syntactic Errors in Configuration: Use this when modifying Exim's configuration file. - exim -C /config/file.new -bV