Hi, I wrote a little script for that which I use in my local CheckMK monitoring platform:
#!/bin/bash
if find /var/lib/docker/volumes/mailcowdockerized_postfix-vol-1/_data/deferred -type f -mmin +20 | grep . >/dev/null
then
COUNT=$(find /var/lib/docker/volumes/mailcowdockerized_postfix-vol-1/_data/deferred -type f -mmin +20 | wc -l)
for mail in $(find /var/lib/docker/volumes/mailcowdockerized_postfix-vol-1/_data/deferred -type f -mmin +20 )
do
DOMAIN="$DOMAIN $(postcat $mail | grep original_recipient | awk '{print $2}' | awk -F@ '{print $2}')"
done
echo "WARNING: $COUNT mails in q, domain(s): $DOMAIN"
exit 1
else
echo "Mail queue ok"
exit 0
fi
It checks for deferred mails older than 20 minutes. Feel free to adapt it