There is nothing available to the scripting processor itself to trigger output of the Error and stack trace.
What is available...
1. SiteToSiteBulletinReportingTask --- This Reporting task can be setup to send all processor produced bulletins over NiFi's S2S protocol to a target NiFi (Target could be same NiFi or NiFI cluster). You could then design a flow that filters out any bulletin with ExecuteScript in it an send that to a putEmail processor to send out a notification when any ExecuteScript processor produces a bulletin. These bulletins will not contain a stack trace if produced. But bulletin would provide necessary information on which node produced error and when that could be used to pull proper log to inspect for stack trace.
*** you may even be able to use bulletin content to parse nifi-app.log and grab the stack trace. Would need to use one of NiFi's scripting processor to do this part.
2. ScriptedReportingTask or scripted --- you may be able to build you own custom script that parses the nifi-app.log looking for ERROR log messages and capture and trailing stack trace. Then have the script send out the email notification. I am not a script writer, so not going to be very helpful here with specifics.