Quick links: qmail-reinject

Some scripts which have been useful at one time or another.


This script, which you can download here, takes messages that are ready for delivery (ie have been preprocessed) and moves them safely into the queued state. For those familiar with the guts of qmail, it moves a queued message from state five to state four.

qmail-send then treats the message as having just been injected and will decide whether it is local or remote and attempt delivery straightaway. You can use this to force delivery of a message at a particular time (theoretically forming the basis of an ETRN system if you were so inclined) or to re-evaluate delivery instructions. For example, imagine we are the secondary MX for domain.tld but the primary, which lives on the end of an ISDN connection, is down more often than not and so qmail-remote fails every time it tries to deliver the message. We can use qmail-reinject to send the message to a local maildir, after setting up appropriate virtual domain rules).

You can reinject a whole swathe of messages in one go with something along the lines of:

for i in $(qmail-queue-view -l | grep 'To: .*@domain.tld' -B3 | sed -n 's/^\([0-9][0-9]*\) .*/\1/p'); do
  qmail-reinject -v $i

Do NOT run this while qmail-send is alive. You'll confuse it.

More scripts may be added later.