20.2.5 Sending Emails from Business Logic
Send templated email from PL/SQL business logic with
APEX_MAIL.SEND.
The equivalent code to send the same email from an Execute Code action looks
like this. No p_from parameter is required because it defaults to using
the value of APP_EMAIL. Notice the p_placeholders parameter expects a JSON
document with the placeholder names and values. The PLIST_TO_JSON_CLOB
function in the APEX_STRING package is handy to produce it. Just pass the
name/value pairs as an APEX_T_VARCHAR2 string list. The values in the odd
positions are the JSON property names and the ones in even positions are the corresponding
values.
apex_mail.send(
p_to => :EMPLOYEE_EMAIL,
p_template_static_id => 'EMPLOYEE_SALARY_LOTTERY_WINNER',
p_placeholders => apex_string.plist_to_json_clob(apex_t_varchar2(
'EMPLOYEE_NAME' , :ENAME,
'NEW_SALARY' , :NEW_SALARY,
'NEW_COMMISSION', :NEW_COMMISSION)));Parent topic: Sending Emails with Templates