I needed to delete an email from the queue today. It kept retrying even though the end user already received multiple copies. :(
Basic steps:
- run mailq to get list of queued messages, note the Q-id
- cd /var/spool/mqueue
- list files and find the one that matches the queued email ID
-- for some reason the file name had an extra couple letters at the front that must mean something.
-- ls *o7UKuGWJ012094* to get files with prepended letters
- remove that file (actually, I moved it to a backup folder)
- run mailq again and see that the message is gone.
Based on: http://lists.freebsd.org/pipermail/freebsd-questions/2004-March/041322.html
Sendmail deferred email?
JJB Barbish3 at adelphia.net
Tue Mar 23 11:21:47 PST 2004
[snip]
Jamie
Thanks for the info
cd /var/spool/mqueue
That is what I was looking for
Deleted all the 15 entries and mailq returns nothing meaning there all gone.
-----Original Message-----
From: Jamie [mailto:jamie at gnulife.org]
Sent: Tuesday, March 23, 2004 2:44 PM
To: JJB
Cc: freebsd-questions at FreeBSD. ORG
Subject: RE: Sendmail deferred email?
[snip]
Check the man page on sendmail. There are a lot of options you can use to process files in the queue. If you have some specific jobs you'd like to process in the queue, you can skip the rest of the queue processing and handle just those.
sendmail -v -qI {queue id substring}
or
sendmail -v -qS {sender address substring}
or
sendmail -v -qR {recipient address substring}
These variations will limit the processing to a sender address, recipient, etc, in the queue.
If you want to simply delete those emails from sendmail, all you have to do is find the numeric part of the queue id, and then remove all files in the queue directory with that ID number. Running mailq will give you a list of the queue id's in the first column:
tags: sendmail, queue, email, remove, clear, delete, stuck,