How to delete messages from mail queue
Here is how to remove mail from the queues of various MTAs. Suppose the queue contains the following messages:
-Queue ID- --Size-- ----Arrival Time---- ---Sender/Recipient-------
9DCE512DB8140 113016 Fri Sep 9 16:49:55 [email protected]
(temporary failure)
[email protected]
A94D912DB80D1 46747 Fri Sep 9 13:48:28 [email protected]
(temporary failure)
[email protected]
D1D0612DB8118 113626 Fri Sep 9 16:47:22 [email protected]
(temporary failure)
[email protected]
Delete mail from the Sendmail queue
-
Delete the files manually from /var/spool/mail/ and /var/mqueue/. Example:
[root@Ezylinux ~]# rm -f /var/spool/mail/*.* [root@Ezylinux ~]# rm -f /var/mqueue/*.*You can also use find to locate the messages to delete. For example, to remove messages with “temporary failure” status from /var/spool/mqueue:
[root@Ezylinux ~]# find /var/spool/mqueue -type f -exec grep "temporary failure" {} \; -exec rm -rf {} \;- Run sendmail as root. Delete the entire mail queue:[root@Ezylinux ~]# sendmail -v -qSpecify the sender domain:[root@Ezylinux ~]# sendmail -qS -v ezylinux.comSpecify the recipient domain:[root@Ezylinux ~]# sendmail -qR -v ezylinux.com
Additional command to view messages in the Sendmail queue:
[root@Ezylinux ~]# mailq
Delete mail from the Postfix queue
For Postfix, use postsuper to delete messages from the mail queue.
- Delete by queue ID using postsuper followed by QueueID, as shown below.
[root@Ezylinux ~]# postsuper -d 9DCE512DB8140 - Delete queued mail for a specified domain.
Specify the sender address. For example, remove messages from [email protected] (sender) from the queue:
[root@Ezylinux ~]# postqueue -p | grep -v '^ *(' | awk 'BEGIN { RS = "" } { if ($7 == "[email protected]") print $1 } ' | tr -d '*!' | postsuper -d -Specify the recipient address. For example, remove messages to [email protected] (recipient) from the queue: [root@Ezylinux ~]# postqueue -p | grep -v ’^ *(’ | awk ‘BEGIN { RS = "" } { if ($8 == “[email protected]” && $9 == "") print $1 } ’ | tr -d ’*!’ | postsuper -d -
** $7=sender, $8=recipient1, $9=recipient2
Additional command to view messages in the Postfix queue:
[root@Ezylinux ~]# postqueue -p
Delete mail from the Exim queue
- Delete by queue ID:
[root@Ezylinux ~]# exim -Mrm D1D0612DB8118 - Delete the entire mail queue:
[root@Ezylinux ~]# exim -bp | awk '/^ *[0-9]+[mhd]/{print "exim -Mrm " $3}' | shor[root@Ezylinux ~]# exim -bp | exiqgrep -i | xargs exim -Mrm - Delete queued mail older than 300 seconds, or 5 minutes:
[root@Ezylinux ~]# exiqgrep -o 300 -i | xargs exim -Mrm
Additional command to view messages in the Exim queue:
[root@Ezylinux ~]# exim -bp
Zimbra Mail Server installation services