How to clear postfix queue
Postfix queue can be cleared using the postsuper command. The syntax is as following:
# postsuper -d ALL
It will clear all the postfix queue. You can specifically clear the deferred emails for example from the postfix queue as following:
# postsuper -d ALL deferred
If you have a large quantity in postfix queue, there is actually a quicker and easier way to do that. You can simply remove all the folders under /var/spool/postfix and it will clear the queue.
# rm -Rf /var/spool/postfix/*
# mailq | tail -n 1
Mail queue is empty
Note: The folders inside postfix would get created automatically once the queue starts filling up, nothing to worry about.
How to clear Exim Queue
Exim queue can be checked using the following:
# exim -bp
To check the number of mails in queue, you can use:
# exim -bpc
To remove a message from exim queue, you need to use the following:
# exim -Mrm {message-id}
There is no build in command to clear all the mails from exim queue. You can use a pipe command to clear the exim queue as following:
# exim -bp | exiqgrep -i | xargs exim -Mrm
Although, there are even quicker and easier way to clear the exim queue, specially if you have a lot of emails in queue and the server is pretty loaded.
# rm -Rf /var/spool/exim/input
Removing the input directory should clear the exim queue. Note: The directory would automatically create once the exim starts it’s queue again, no need to worry.