ORA-20001: This procedure must be invoked from within an application session.
You're not running it in a valid APEX session.
The code that you need to run in order to set up an APEX session in order for APEX_MAIL to work is easily found.
All you have to do is Read The Fabulous Manual. APEX_MAIL
Why it "works fine in development" when you did not set an APEX session is beyond me.
Since documentation states that your code should fail, I would classify your Development has having a bug, not Test.
Thanks for the replies (even for the RTFM ones although my question wasn't about the code but rather about the differences in behavior across environments)
Anyway I found out what was wrong. My application schema is SCHEMA1, however to send emails it calls a package in SCHEMA2 (which in turn calls APEX_MAIL).
In the development environment, both schemas are set up as parsing schemas in APEX. In the test environment though, only SCHEMA1 was set up as such, that is why the code didn't work there I guess.
By the way, I read the manual and the APEX documentation doesn't mention anything about running a "valid apex session" before sending emails; all you need is a valid workspace ID. The error message is very misleading in my opinion.