If an out-going email message gets stuck in postfix’s deferred queue due to a malformed To: (recipient) address, there are a couple of ways to deal with it.
First one is courtesy of Mattias (@mattiasgeniar), who introduced the
postcat -h -b command (thanks Mattias!) to extract the queued message’s headers and body to a temporary file, then used that file as an input to sendmail:
sendmail -f firstname.lastname@example.org email@example.com
Others suggest to use postfix’s
smtp_generic_maps in the
main.cf file to rewrite the message next time delivery is attempted.
This method ought to work, but it wasn’t working as expected and the reason for this post is to help explain why, and how to overcome the issue.
In brief: since the queued message was addressed To: firstname.lastname@example.org and
$mydestination did not include www.example.com, the rewriting rules in
/etc/postfix/generic were not being invoked.
There’s a subtle hint in the postfix documentation:
TABLE SEARCH ORDER
Replace user@site by address when site is equal to $myorigin, when site is listed in $mydestination, or...
It’s still unclear why the preceding stanza in the documentation didn’t work:
user@domain address Replace user@domain by address. This form has the highest prece- dence.
main.cf to append “
, www.example.com” to the
$mydestination= line, creating an
/etc/postfix/generic file and running
postmap generic in the
/etc/postfix folder, then, finally, running
postfix reload, and finally the queue cleared.
It could be argued that Mattias’s method is better / more elegant (noteworthy: it preserved the date/time of the outgoing message), the latter method might be preferable for a large quantity of messages or a more permanent solution to a recurring issue.
One should investigate why the malformed messages are being generated and rectify that (“Hello,
Happy computing, hope this helps someone…