You can use the mailq command sendmail -bp command to display a summary of the mail messages queued for future delivery. Type the following command:
# mailq
OR
# sendmail -bp
Sample outputs:
/var/spool/mqueue (1 request)You can cd to /var/spool/mqueue and delete all files if you want to get rid of all messages in the queue:
-----Q-ID----- --Size-- -----Q-Time----- ------------Sender/Recipient-----------
p61J75u5037681 893 Fri Jul 1 14:07
8BITMIME (Deferred: Connection timed out with example.com.)
Total requests: 1
# cd /var/spool/mqueue/
# ls
# rm *
qtool.pl Tool
Sendmail mail server does not provide any command to remove messages from the mail queue. The above will delete all messages from the mail queue. You can use qtool.pl script located in sendmail source code contrib directory as follows:# mailq
Sample outputs:
/var/spool/mqueue (1 request)Note down Q-ID p61J75u5037681 and run qtool.pl as follows:
-----Q-ID----- --Size-- -----Q-Time----- ------------Sender/Recipient-----------
p61J75u5037681 893 Fri Jul 1 14:07
8BITMIME (Deferred: Connection timed out with example.com.)
Total requests: 1
# ./qtool.pl -C /etc/mail/sendmail.cf -d /var/spool/mqueue/p61J75u5037681
Where,
- -C /etc/mail/sendmail.cf - Specify sendmail config file.
- -d /var/spool/mqueue/p61J75u5037681 - Delete the messages specified by source. In this case by Q-ID.
OR
QIDS="qid1 qid2 qidN"
Use the following bash for loop to delete all messages for example.com:
QIDS="$(mailq | grep -B1 'example.com' | grep '^[a-z]' | awk '{print $1}' | sed 's/\*$//')"
for q in $QIDS
do
/usr/local/bin/qtool.pl -C /etc/mail/sendmail.cf -d /var/spool/mqueue/$q
done
No comments:
Post a Comment