Operating System - HP-UX
1823180 Members
3717 Online
109647 Solutions
New Discussion юеВ

Re: Clearing the mail queue?

 
SOLVED
Go to solution
Patrick Ware_1
Super Advisor

Clearing the mail queue?

Hello,

It has been a while since I had to deal with mail on a UNIX host. Well, issued a mailq command on my system, and there is a lot of undelivered mail. How do I clear out the queue, as I don't want these massages to be sent?

Thanks in advance!
8 REPLIES 8
Tim Nelson
Honored Contributor

Re: Clearing the mail queue?

/var/spool/mqueue has all the mail in the queue.

delete the files in it.

Ivan Krastev
Honored Contributor

Re: Clearing the mail queue?

Here is also old thread about mqueue handling - http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=853749

You can clean up it periodicaly.


regards,
ivan
Steven E. Protter
Exalted Contributor

Re: Clearing the mail queue?

Shalom,

If access to the Internet is normal,and DNS resolution is good, most mail will be delivered in seconds.

sendmail -v -q

This will attempt to run the queue and provide verbose output for failures. You should look at some of the failures before manually clearing the mail queue.

You may find spam or something you should research before sending it to the bit bucket.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
whiteknight
Honored Contributor
Solution

Re: Clearing the mail queue?

Patrick,

mail-queue in the directory /var/spool/mqueue. In this directory the messages can be refound with help of the Q-ID. Each message consists of two files:

qfNAAnnnn -- Job control file (header infos)
dfNAAnnnn -- Data file (message body)

If you want to delete a message you just have to get the Q-ID with the command mailq, then you can delete the belonging qf and df file in the directory /var/spool/mqueue.

WK
Problem never ends, you must know how to fix it
Dennis Handly
Acclaimed Contributor

Re: Clearing the mail queue?

If you use vi on the mqueue files, if you are ambitious you could redirect the mail output by changing the appropriate lines in qfNAAnnnn.

If you don't want them, in vi you could just use:
:!rm %
Then ":n" to go to the next.
Patrick Ware_1
Super Advisor

Re: Clearing the mail queue?

Thanks guys! I ran mailq through an inefficient for loop, and grepped out the lines I didn't want to see, (like e-mail addresses, which are not shown here).

for i in `mailq |grep -v Deferred |grep -v mqueue |grep -v - |awk '{print $1}'`
do
rm /var/spool/mqueue/df$i
rm /var/spool/mqueue/qf$i
done

# mailq
/var/spool/mqueue is empty
Geoff Wild
Honored Contributor

Re: Clearing the mail queue?

Here's how I do it on my linux server:

/usr/bin/find /var/spool/mqueue/ -mtime 1 |xargs rm -f {}; > /tmp/cleanmqueue.cron.log 2>&1

For cleanliness, restart sendmail...

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Sandman!
Honored Contributor

Re: Clearing the mail queue?

You can avoid the for-loop by leveraging awk's built-in loop for the same effect:

# ls -1 /var/spool/mqueue/* | xargs rm