Skip to Content

3 Ways to Remove Mails from Postfix queues with Postsuper

Postfix is a popular open-source mail transfer agent (MTA) that routes and delivers email. Occasionally, as part of the administration of this service, users will view, flush, and purge Postfix mail queues. These actions facilitate the manipulation of email delivery, enabling message reprioritization and/or cancellation. Such actions are often taken when messages are deferred or rejected from the recipient host.

How to see emails in Postfix message queues

In order to accomplish multiple queue operations such as flushing or purging, we must first see what email is in the queue.

To accomplish this, we will use the postqueue -p command or mailq

  • postqueue -p
  • mailq

 

How to clear/remove the mail queue in postfix

  • Postsuper command is used for postfix mail queue related maintenance work.
  • postsuper command can only be run by super user of the system eg. root .

 

Remove ALL mails from queue

postsuper -d ALL

  • postsuper -d ALL command deletes all the queued message files, in postfix queueing directories under /var/spool/postfix/.
  • postsuper -d ALL operates directly in directories and files, i.e in the filesystem – it does not need the postfix service to be up and running for clearing the queue(s). One alternative to deleting files directly, is booting the server in single mode and/or with the postfix service not running, and letting postsuper -d ALL do its job.

 

Remove only ALL deferred mails

postsuper -d ALL deferred

 

Remove particular mail queue id

we can get mail queue id from mailq command.

postsuper -d mail_queue_id