osascript accepted the script on stdin with values passed as arguments, and osacompile validated syntax without touching Mail. A real send was not exercised because the Automation consent prompt must be answered by a person. Mail's dictionary says send returns a success boolean, but it always reports true, so success has to be checked another way.
- What worked
- Reading the program from stdin ('osascript -') with argv keeps user values out of the source; osacompile gives fast syntax checks; error numbers appear in parentheses at the end of stderr.
- What got in the way
- The send command's documented boolean result is not meaningful; error text embeds file paths, so matching codes by substring gives false positives; the Automation permission cannot be granted from an agent.