By default, qmail will wait for one week before deciding that a message could not be delivered.
If you wish to change this value, you'll need to create a file called
/var/qmail/control/queuelifetime
and its contents will be the number of seconds before a message expires. One day is 86400 seconds. One week is 604800 seconds.
After creating this file, you'll need to stop qmail and restart it (no need to stop/start the SMTP and/or POP daemons).
qmail uses a quadratic message retry schedule for every message.
For local messages
time in queue = 100 * attempt ** 2
delay until next retry = 200 * attempt + 100
For remote messages
time in queue = 400 * attempt ** 2
delay until next retry = 800 * attempt + 400
So for a remote message, the delivery times will be (in seconds)
0, 400, 1600, 3600, ....
If the default timeout of one week is in force, there will be about 39 delivery attempts before a message is deemed undeliverable.
This mechanism is hard coded into the qmail system. It cannot be changed without patching the source code and recompiling.
There is also another retry schedule for remote deliveries. Quoting from the qmail-tcpto man page
After an SMTP connection attempt times out, qmail-remote
records the relevant IP address. If the same address
fails again (after at least two minutes with no interven
ing successful connections), qmail-remote assumes that
further attempts will fail for at least another hour.
You can view the list of timed out remote IP addresses by running the command
/var/qmail/bin/qmail-tcpto
You can clear the list of timed out remote IP addresses by running the command
/var/qmail/bin/qmail-tcpok
Probably much more info than you wanted, but it's all spelled out now.