[ Update per 2021-10-20:
As outlined in my comment to your original question from 2021-10-20, there is an alternative way around the problem which saves you from recompiling: Move the "real" sendmail elsewhere and install the scripts in its place. Then, whenever the script is executed, make it figure out who called it. If cron has called it, make it behave as shown above; if not, make it call the "real" sendmail with the same stdin and parameters, i.e. "relay" stdin and the parameters to the "real" sendmail.
]
Another problem is that you don't see only the error messages you're interested in, but each time see the whole raw email message cron would send, including the headers. The remedy would be to add some code to our script which filters out the lines you are not interested in, e.g. using grep, sed and their friends. But this also is outside the scope of this question.