Ok, so TextExpander specific, and likely that app isn’t asking for the permission.
I think when it does so, the Mail app should appear under the
Preferences > Security & Privacy > Privacy > Automation > TextExpander settings. I just don’t know if TextExpander is set-up to prompt for this (I do use TextExpander, but not Mail.app).
At one point you could use a utility to push things in via the command line, but security restrictions have (rightly) locked that down. I don’t think there’s a way around that except to get Smile to add something in; though maybe some other way does exist that someone else can suggest?
You can of course reset the Apple Events permissions database via the command line.
tccutil reset AppleEvents
But if TextExpander doesn’t ask for permission, then you’re a few steps back as you’ll have to reauthorise everything. However if TextExpander does support asking for the permission, this is the right way to proceed.
As a workaround, I’m wondering if you could save your AppleScript, and then use a shell script in TextExpander to call it via
osascript? I think that could put it into the realm of indirect access and so it wouldn’t be TextExpander asking for access, but your shell. Might be worth a try