Did you include wwv_flow_mail.push_queue in your code.
Also when I had a similar issue I once execute the send mail procedure in Oracle Apex Sql commands editor. It started working.
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.
Agree with Mike. No way the above code worked for you as is.
It's unsupported hackery but, should work for you.
If the Fabulous Manual tells you to run a particular piece of code to get APEX_MAIL to work outside of the APEX environment....
Why are you posting a non-supported hack?
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.