Operating System - HP-UX
1820390 Members
3769 Online
109623 Solutions
New Discussion юеВ

sendmail - deleting queued messages

 
S.Rider
Regular Advisor

sendmail - deleting queued messages

I have multiple queued mails cause by invalid/obsolete addresses. There must be a more gracefull way to delete then besides rm'ing the df* and qf* files in /var/spool/mqueue ?
Ride Boldly Ride, but watch out for El Dorado's
6 REPLIES 6
Steven E. Protter
Exalted Contributor

Re: sendmail - deleting queued messages

I guess you'd have to define graceful.

You could let them sit there until they sit longer than whatever parameters you have in sendmail.cf for attempted mail delivery.

Somewhat more graceful would be doing a find with the +mtime paramter and have a cron job delete them after they are say 2 days old.

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
Bejoy C Alias
Respected Contributor

Re: sendmail - deleting queued messages

If u want to delete the mails regularly then u may need to create cron jobs to remove the files from the /var/spool/mqueue directory which is more than xx days old . If it is a one time need, then u can simply rm the files qf[xxx] and df[xxx] where the xxx is the unique id of the mails u get for each mail in the left most when u execute the mailq command . U can select those numbers of the unneeded mails from mailq and rm those files.
Be Always Joy ......
Geoff Wild
Honored Contributor

Re: sendmail - deleting queued messages

If you want to delete the queue - then shutdown sendmail first (if running) then delete files in /var/spool/mqueue, then restart sendmail (if needed)...

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.
Doug O'Leary
Honored Contributor

Re: sendmail - deleting queued messages

Hey;

Get a list of ids, either through grep'ing the patter out of mailq or running mailq or sending to a file.

for id in $(cat ${file-o-ids})
do
rm /var/spool/mqueue/[qd]${id}
done

HTH;

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
Rick Garland
Honored Contributor

Re: sendmail - deleting queued messages

All that is necessary is deleting files in the /var/spool/mqueue.

I leave sendmail off so the deletion can be at any time. Don't know about shutting down, deleting, and restarting.

Ermin Borovac
Honored Contributor

Re: sendmail - deleting queued messages

Sendmail source contains tool you may find useful. It's called qtool.pl and it's in the contrib directory.

NAME
qtool - manipulate sendmail queues

SYNOPSIS
qtool.pl [options] target_directory source [source ...]

qtool.pl [-Q][-d|-b] [options] source [source ...]

DESCRIPTION
Qtool moves the queue files used by sendmail between queues. It uses
the same locking mechanism as sendmail so can be safely used while
sendmail is running.

$ ./qtool.pl
The destination '' must be an existing directory.
Usage: ./qtool.pl [options] directory source ...
./qtool.pl [-Q][-d|-b] source ...
Options:
-b Bounce the messages specified by source.
-C configfile Specify sendmail config file.
-d Delete the messages specified by source.
-e [perl expression]
Move only messages for which perl expression
returns true.
-Q Operate on quarantined files.
-s [seconds] Move only messages whose queue file is older
than seconds.