Postfix queue gets email stuck, the email should now be redirected to another recipient! Such a scenario can occur if no emails can be delivered to the original recipient address, for example when the mailbox space limit is reached, or the server responds with an error or there are the server is unreachable.
Here it can be helpful to temporarily send the email to another recipient. The tutorial shows the steps for delivering an e-mail remaining in the Postfix queue to an alternative recipient.
How to redirect queued mail to recipient
First, you look for the queue ID of the e-mail in the Postfix queue, which you want to send to another recipient address.
$ postqueue -p | grep 'firstname.lastname@example.org' -B 2
The parameter -B 2 outputs two additional lines before the parse.
The output can look similar to the following.
BCD2C3035D31! 37023 Thu Feb 17 08:59:55 email@example.com (connect to 126.96.36.199[188.8.131.52]:25: Connection timed out) firstname.lastname@example.org
Here an e-mail was sent to email@example.com which I want to deliver to a different address. The queue ID is
BCD2C3035D31 which we need.
Alternatively, you can simply listing emails in the Postfix queues.
To prevent Postfix from trying to deliver the deffered email in the meantime, we set it to on hold with the -h option.
$ postsuper -h BCD2C3035D31 postsuper: BCD2C3035D31: placed on hold postsuper: Placed on hold: 1 message
The e-mails are not deleted with on hold. The exclamation mark (!) indicates that the message is on hold.
Now you extract the e-mail and save it to a temporary file.
$ postcat -qbh BCD2C3035D31 > /tmp/email.eml
Now that the email is extracted, you can send it to a different recipient than the original.
$ sendmail -f firstname.lastname@example.org email@example.com < /tmp/email.eml
The e-mail will be sent from firstname.lastname@example.org to email@example.com.
Search the Postfix deffered queue for pending emails.
$ postqueue -vp
After the delivery to the new e-mail address has been confirmed, the e-mail can be removed from the Postfix queue.
$ postsuper -d BCD2C3035D31 postsuper: BCD2C3035D31: removed postsuper: Deleted: 1 message
Delete the temporary /tmp/email.eml file.
$ rm -f /tmp/email.eml
Postfix helpful commands
Hint! To show Postfix queued e-mail contents.
$ postcat -vq BCD2C3035D31
Release mail that was put “on hold”.
$ postsuper -H BCD2C3035D31 postsuper: BCD2C3035D31: released from hold postsuper: Released from hold: 1 message
Flush the queue, attempt to deliver all queued mail.
$ postqueue -f
To remove all e-mails in the Postfix deferred queue.
$ postsuper -d ALL deferred
As shown in this tutorial, it is possible to set e-mails from the Postfix queue to Hold, temporarily deliver them to other recipients, and remaining e-mails can also be removed from the queue for system hygiene.
We are sorry that this post was not useful for you!
Let us improve this post!
Tell us how we can improve this post?