[SOLVED] Selectively delete many mails from queue

wwweiss

Well-Known Member
Apr 28, 2018
31
6
48
64
Inside the Web-Admin it is very easy to look to the queues. Very often I see a lot of mails that should be deleted (maybe a customer makes something wrong which causes a few thousand mails hanging in the queue). What I would like to do is to delete all mails of a filtered view, maybe a Button "deleted all" which referes to the filter result or the option to mark many mails inside a list (typical select options with shift or ctrl) and then delete the marked mails - same as deleting a single mail.
Is this function already available and a do not see it or is this something for the wishlist?
Is there any posibility to do that via ssh?
 
You can delete _all_ messages in the queue (in the summary tab)
a multiselect in the deferred queue listing is not available - please create an enhancement request over at our bugzilla: https://bugzilla.proxmox.com
with a rationale, why you would want this

Is there any posibility to do that via ssh?
yes - the `mailq` command lists all mails in the queue - with `awk` you can print the message ids matching a particular sender and use `postsuper -d` to delete all such mails - see the manpage of postsuper (`man postsuper`) for an example.

as an alternative you could also use `postqueue` json output and jq to filter mails for deletion - e.g.:
Code:
 postqueue -j | jq 'select(.sender=="spammer@domain.com")|.queue_id'|sed -r 's/^\"(.*)\"$/\1/' | postsuper -d -

to delete mail from spammer@domain.com

I hope this helps!
 
  • Like
Reactions: dmlc and hata_ph
Thank you very much. Again I see my basic linux knowledge is not as it should be. Having this very good example helped so much in understanding mailq and postqueue. I was able to delete the mails I wanted, just using your code example :)
And yes I will post an enhancement request.
 
  • Like
Reactions: Stoiko Ivanov
You can delete _all_ messages in the queue (in the summary tab)
a multiselect in the deferred queue listing is not available - please create an enhancement request over at our bugzilla: https://bugzilla.proxmox.com
with a rationale, why you would want this


yes - the `mailq` command lists all mails in the queue - with `awk` you can print the message ids matching a particular sender and use `postsuper -d` to delete all such mails - see the manpage of postsuper (`man postsuper`) for an example.

as an alternative you could also use `postqueue` json output and jq to filter mails for deletion - e.g.:
Code:
 postqueue -j | jq 'select(.sender=="spammer@domain.com")|.queue_id'|sed -r 's/^\"(.*)\"$/\1/' | postsuper -d -

to delete mail from spammer@domain.com

I hope this helps!

if you use `jq -r` you don't need the sed -r, so the command is
Code:
 postqueue -j | jq -r 'select(.sender=="spammer@domain.com")|.queue_id' | postsuper -d -

but thanks for the command, a bit faster then about 800 times select mail, and click delete
 
  • Like
Reactions: Stoiko Ivanov