### check_mailqueue
Command:
/usr/local/nagios/libexec/check_nrpe -H localhost -c check_mailqueue
This checks the email queue status.
—
### Exim Commands for Mail Queue
– **Check Mail Count**:
“`
exim -bpc
“`
This command shows the total count of emails in the queue.
– **View Mail List**:
“`
exim -bp
“`
This displays the list of all emails in the queue.
– **View Mail Header**:
“`
exim -Mvh <mailID>
“`
Displays the header of a specific email.
– **View Mail Body**:
“`
exim -Mvb <mailID>
“`
Displays the body of a specific email.
– **Force Full Email Send**:
“`
exim -qff -v -C /etc/exim.conf
“`
Forces the delivery of all queued emails.
– **Delete Frozen Messages**:
“`
exim -bp | grep frozen | awk {‘print $3’} | xargs exim -Mrm
“`
– **Delete “fbpm” Messages**:
“`
exim -bp | grep “fbpm” | awk {‘print $3’} | xargs exim -Mrm
“`
– **Delete Emails of Specific Users**:
“`
exim -bp | grep “username” | awk {‘print $3’} | xargs exim -Mrm
“`
– **Delete All Emails from Queue**:
“`
exim -bp | awk ‘/^ *[0-9]+[mhd]/{print “exim -Mrm ” $3}’ | bash
“`
– **Search Mail Log for Specific Mail ID**:
“`
exigrep <mailID> /var/log/exim_mainlog
“`
– **Get Email Subject from Log**:
“`
grep -oP ‘T=\K”[^”]+”‘ /var/log/exim_mainlog
“`
– **Exclude Specific Subject in Log**:
“`
grep ‘ <= ‘ /var/log/exim_mainlog | grep -v ‘Web server cp1.superior-host.com on cp1.superior-host.com\\n automatically restarted’ | grep -oP ‘T=\K”[^”]+”‘
“`
– **Remove All Emails from Queue**:
“`
exim -bp | awk ‘{print $3}’ | sed ‘s/[<>]//g’ | xargs -I {} exim -Mrm {}
“`
—
### check_postqueue
– **Check Mail Count in Postfix**:
“`
postqueue -p | grep -c “^[A-Z0-9]”
“`
– **View Mail Queue**:
“`
postqueue -p
“`
– **View Postfix Mail Header and Body**:
“`
postcat -q <ID>
“`
– **Delete Frozen Emails in Postfix**:
“`
postsuper -d ALL deferred
“`
– **Force Full Email Send in Postfix**:
“`
postsuper -r ALL && postqueue -f
“`
– **Remove Specific Mail from Postfix Queue**:
“`
postqueue -p | awk ‘BEGIN { RS = “” } /[email protected]/ { print $1 }’ | postsuper -d –
“`
—
### check_mailcount_hour
Command:
“`
/usr/local/nagios/libexec/check_nrpe -H localhost -c check_mailcount_hour
“`
This checks the mail count for the last hour.
– **Search for Specific Mail ID in Exim Log**:
“`
grep ***mail_id*** /var/log/exim_mainlog
“`
– **Find Specific User’s Mails**:
“`
tail -f /var/log/exim_mainlog | grep username
“`
– **Check if Mails are Sent via Scripts**:
“`
grep -i post /usr/local/apache/domlogs/stainbus/* | cut -d ” ” -f7 | sort | uniq -c | sort -n
“`
– **Check Mails from Contact Forms**:
“`
cat /usr/local/apache/domlogs/USERNAME/* | grep CONTACTFORM_NAME
“`
– **Check for Scripts Sending Spam Mails**:
“`
awk ‘$3 ~ /^cwd/{print $3}’ /var/log/exim_mainlog | sort | uniq -c | sed “s|^ *||g” | sort -nr
“`
—
### Exim Mail Sender Details
– **Get Sorted List of Mail Senders**:
“`
exim -bpr | grep “<” | awk {‘print $4’} | cut -d “<” -f 2 | cut -d “>” -f 1 | sort -n | uniq -c | sort -n
“`
– **Get Mail Information by User**:
“`
csf -g IP
“`
“`
cat /var/log/maillog | grep usermail
“`
“`
tail -f /var/log/maillog | grep emailid
“`
—
### check_dovecotcon
– **View Dovecot Connection Logs**:
“`
exim -bp ID
exim -Mvh ID
exim -Mvb ID
“`
– **Search for Specific Mail ID in Logs**:
“`
grep ****mailid**** /var/log/maillog
grep ***id*** /var/log/exim_mainlog
“`
– **Clear Log by Tar if Mails Are Genuine**.
– **Change Password if Dovecot Logins Are High**.
—
# Notes
– Always verify mails in the queue before deleting.
– Use `tail -f` to monitor real-time logs.
– Take necessary actions based on the type of issue, such as spam detection or genuine email delivery issues.