• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Contribution How-To monitor mail queue on Plesk 11.X and get informed when queue exceeds limit

HMoellendorf87

Regular Pleskian
Dear community,

as some customer asked for a solution for monitoring the mail queue on the plesk server, I found one and I think this is in some cases useful. So I try to get a manual written down here, afterwards I will add also pictures.

Requirements
1.) Login via SSH possible
2.) Knowledge about text-editor on your machine
3.) Knowledge about cronjobs

Steps

1. Step
Login to your server using root access.

2. Step
Create a file named check_email_queue.sh by using an text-editor, i.e. vi or nano and switch to INSERT mode (in vi)

3. Step
Fill in the following code:

#!/bin/bash

# get server hostname
hostname=`cat /etc/hostname`

current_mailq=`postqueue -p | tail -n 1 | cut -d' ' -f5`

yourEmail="[email protected]"


if [ "$current_mailq" -gt "100" ]
then
echo "Mail queue problem - there is currently $current_mailq mails in queue. Please check it out." > check_email_queue_outgoing.txt
mail -s "$hostname - mail queue alert - there are $current_mailq emails in queue" "$yourEmail" < check_email_queue_outgoing.txt
else
echo "Mail queue is fine - there is currently $current_mailq mails in queue. Please check it out."
echo "Do nothing, situation is fine."
fi

The bold parameters have to be edited to your information and requirement.
Save the file and quit your editor

4. Step

Now you have to setup your cronjob using the following command:

crontab -e

5. Step
Enter the following line and adapt the aquired time to run your crontab requirements:
*/5 * * * * cd /home/user/ && ./check_email_queue.sh

This script runs now every 5 minutes and checks your mail queue and will inform you via mail as soon the mail queue limit exceeds.


Thanks to MislavOhttp://forum.parallels.com/member.php?131175-MislavO.

Any questions or feature requests are appreciated.
 
Last edited:
If your email_queue ihave 10000 emails, this way to send to you a mail is not helpful. Will be go to the end of the queue and you will get this mail when is too late :-(
 
I've modified the code so that alerts are pushed via Pushbullet as this is practically useless in situations when your queue gets hit HARD. You'll want to download the app on a mobile device, and setup your own API key. Code follows;

Code:
#!/bin/bash

# get server hostname
hostname=`hostname`

current_mailq=`postqueue -p | tail -n 1 | cut -d' ' -f5`

API_KEY="YOUR_API_KEY_GOES_HERE"

if [ "$current_mailq" -gt "100" ]
then
curl -u $API_KEY: https://api.pushbullet.com/v2/pushes -d type=note -d title="Alert for $hostname" -d body="There are $current_mailq emails in queue"
else
echo "Mail queue is fine - there is currently $current_mailq mails in queue."
fi
 
Back
Top