[TUTORIAL] Send notification email if some mail in Queue Administration with Reason "452..." or over threshold of number of messages

poetry

Active Member
May 28, 2020
206
63
33
Hello,

We are seeing that a good indication that something is not working when messages are starting to accumulate on our incoming mail filter.
Is it possible to create some rule so we would be notified if messages in Queue reach a specific threshold like more then 50 messages in Queue waiting for delivery or if we can set strings that will match the reason for example here is one on the image below
sub.png

Thank you!
 
Use system monitoring tool like nagios to monitor your pmg system load or mail queue.
 
I managed to do this with a simple bash script and it does exactly what I wanted. I modified the original script to send information about the queue in the body.
This link was very helpful: https://mailmum.io/posts/monitoring-postfix-email-queue-with-push-notifications/
Here info about the script and some commands:

apt install gawk
whereis -l postqueue
chmod +x /usr/local/sbin/mailqueue_size.sh

Script:
nano /usr/local/sbin/mailqueue_size.sh

Bash:
#!/bin/bash

mailq_count="$(/usr/bin/mailq | /usr/bin/tail -n1 | /usr/bin/gawk '{print $5}')"
mailq_reason="$(/usr/sbin/postqueue -p)"

# If variable is empty, then the queue is empty -> set it to zero
if [ -z "$mailq_count" ]; then
  mailq_count=0
fi

if [ "$mailq_count" -gt 20 ]; then
  echo " ${mailq_reason} " | /usr/bin/mail -s "${mailq_count} <- this many messages are waiting for delivery on server.example.com " example@example.com
fi

Cron:
nano /etc/cron.d/mailqueue-watchdog
Code:
*/5 *  * * *   root    nice -n 19  /usr/local/sbin/mailqueue_size.sh
 
Thanks for sharing the idea.

I wonder if there is a command to add a user to the blacklist to immediately block the sender when the number of messages in the queue is too large.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!