Saturday, April 15, 2017


How to Flush Mail Queue in Linux

# mailq

# sendmail -bp

Sample Outputs


                /var/spool/mqueue (3 requests)

-----Q-ID----- --Size-- -----Q-Time----- ------------Sender/Recipient-----------
v3G31Qbu031236      147 Sun Apr 16 08:31 <root@ebis.expolanka.com>
                 (host map: lookup (expolanka.com): deferred)
                                         <dbateam@expolanka.com>

You can cd to /var/spool/mqueue and delete all files if you want to get rid of all messages in the queue:

# cd /var/spool/mqueue/
# ls
# rm *

 # /etc/init.d/sendmail restart

----------------------------------------------------------------------------------------------------------------------

vi /etc/mail/mailertable

expolanka.com esmtp:[10.2.20.160]


restart sendmail

----------------------------------------------------------------------------------------------------------------------

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 scriptlocated in sendmail source code contrib directory as follows:
# mailq
Sample outputs:
  /var/spool/mqueue (1 request)
-----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
Note down Q-ID p61J75u5037681 and run qtool.pl as follows:
# ./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.
  • To delete all messages queued for the example.com domain. First, you need to set QIDS either using the mailq command or manually as follows:
    QIDS="qid1 qid2 qidN"
    OR
    QIDS="$(mailq | grep -B1 'example.com' | grep '^[a-z]'  | awk  '{print $1}' | sed  's/\*$//')"
    Use the following bash for loop to delete all messages for example.com:
    for q in $QIDS
    do
      /usr/local/bin/qtool.pl -C /etc/mail/sendmail.cf -d /var/spool/mqueue/$q
    done

    More links and information:




No comments:

Post a Comment

  RMAN-20207: UNTIL TIME or RECOVERY WINDOW is before RESETLOGS time https://shivanandarao-oracle.com/2012/12/05/rman-20207-until-time-or-re...