Integrating Oracle APEX Email Templates, Dynamic Placeholders, Product Images, and APEX_MAIL
1. Introduction
Email communication is an essential part of modern business applications. Organizations frequently need to share product information, quotations, promotional details, and business updates with customers through professional email templates.
Oracle APEX provides built-in email functionality that allows developers to create reusable email templates and send dynamic content using PL/SQL.
In this article, I will demonstrate how to send an email from Oracle APEX using an email template that includes product information and a product image.
The application allows users to select a product, preview its information and image, enter a recipientβs email address, and send a professionally structured email containing dynamic product details.
This implementation demonstrates how Oracle APEX Email Templates can be integrated with APEX_MAIL, APEX_JSON, SQL, and PL/SQL to build a practical email communication solution.
2. Project Overview
The application is designed to send product information through an Oracle APEX email template.
The user selects a product from a dropdown list. The application automatically refreshes the Product Details report to display the selected productβs information and image.
After entering the recipientβs email address, the user clicks the Send Email button. Oracle APEX retrieves the product information, prepares dynamic email placeholders, generates the product image URL, and sends the email using the configured email template.
Main Features
-
Select a product from a dropdown list.
-
Display product information dynamically.
-
Preview the selected product image.
-
Enter the recipientβs email address.
-
Generate a dynamic product image URL.
-
Prepare email placeholders using APEX_JSON.
-
Send emails using Oracle APEX Email Templates.
-
Send emails using the APEX_MAIL package.
-
Push queued emails for delivery.
3. Application Architecture
The implementation combines Oracle APEX components with database and email functionality.
| Component | Purpose |
|---|---|
| Oracle APEX | Main email interface |
| Product Select List | Selects a product |
| Product Details Report | Displays product information and image |
| Dynamic Action | Refreshes the report when product changes |
| Send Email Button | Submits the email request |
| PL/SQL Process | Prepares email content and sends email |
| APEX_JSON | Creates dynamic email placeholders |
| APEX_MAIL | Sends the email |
| Email Template | Defines the reusable email layout |
| AUW_PRODUCTS | Stores product information and images |
4. Database Structure
The application uses an existing database table named AUW_PRODUCTS.
The page export references the following columns:
| Column | Purpose |
|---|---|
| PRODUCT_ID | Unique product identifier |
| PRODUCT_NAME | Product name |
| PRODUCT_DESCRIPTION | Product description |
| CATEGORY | Product category |
| PRODUCT_IMAGE | Stores product image |
The product image is stored in the PRODUCT_IMAGE column and retrieved for display in the report.
The export references this existing table; its original DDL is not included in the supplied page export.
5. Creating the Product Selection Interface
The application contains a Select List item named:
P7_PRODUCT_ID
This item allows users to select a product from the AUW_PRODUCTS table.
LOV SQL Query
SELECT
PRODUCT_NAME AS DISPLAY_VALUE,
PRODUCT_ID AS RETURN_VALUE
FROM AUW_PRODUCTS
ORDER BY PRODUCT_NAME;
When a user selects a product, its ID is stored in the page item.
This value is then used by the Product Details report to retrieve the corresponding product information.
6. Displaying Product Details and Image
The application uses a SQL Report region named:
Product Details
The report retrieves product information based on the selected product ID.
SQL Query
SELECT
PRODUCT_ID,
PRODUCT_NAME,
PRODUCT_DESCRIPTION,
CATEGORY,
DBMS_LOB.GETLENGTH(PRODUCT_IMAGE) PREVIEW
FROM AUW_PRODUCTS
WHERE PRODUCT_ID = :P7_PRODUCT_ID;
The report includes the following information:
-
Product ID
-
Product Name
-
Product Description
-
Category
-
Product Image Preview
The image column uses Oracle APEXβs report image formatting:
IMAGE:AUW_PRODUCTS:PRODUCT_IMAGE:PRODUCT_ID::MIMETYPE:FILENAME:IMAGE_LAST_UPDATE::::
This allows the report to display the image stored in the database.
7. Automatically Refreshing Product Information
To display the correct product information, the application uses a Dynamic Action.
Dynamic Action Name: Refresh Products Report
Configuration:
| Property | Value |
|---|---|
| Event | Change |
| Selection Type | Item |
| Item | P7_PRODUCT_ID |
| Action | Refresh |
| Affected Region | Product Details |
Whenever the user selects a different product, the report refreshes automatically.
There is no need to submit the entire page just to display the selected productβs information.
8. Creating the Email Input and Send Button
The application provides an email input item:
P7_EMAIL_TO
This item collects the recipientβs email address and is configured as a required field.
The page also contains a button:
SEND_EMAIL
When the user clicks this button, Oracle APEX submits the page and executes the associated PL/SQL process.
The process is configured to run only when the SEND_EMAIL button is submitted.
9. Understanding Oracle APEX Email Templates
Oracle APEX Email Templates allow developers to define reusable email layouts.
Instead of writing the entire email HTML inside every PL/SQL process, developers can define an email template and populate its dynamic placeholders at runtime.
For this implementation, the email template uses the following Static ID:
INCLUDING_IMAGES
The application prepares the following placeholders:
| Placeholder | Description |
|---|---|
| APPLICATION_LINK | Application URL |
| CATEGORY | Product category |
| PRODUCT_DESCRIPTION | Product description |
| PRODUCT_NAME | Product name |
| PROD_IMAGE_URL | Product image URL |
These placeholders allow the same email template to display different product information depending on the userβs selection.
The email templateβs actual HTML definition is not included in this Page 7 export, but the PL/SQL process shows the Static ID and all five placeholder names used.
10. Generating the Product Image URL
One of the important parts of this implementation is generating a URL for the selected product image.
The application uses the following PL/SQL expression:
l_prod_image_url :=
apex_mail.get_instance_url
|| apex_page.get_url(
p_page => 999,
p_items => 'P999_PRODUCT_ID',
p_values => :P7_PRODUCT_ID
);
This generates an application URL pointing to Page 999 and passes the selected product ID through the P999_PRODUCT_ID item.
The generated URL is assigned to the PROD_IMAGE_URL email placeholder.
This allows the email template to reference the product image through a URL instead of embedding the image BLOB directly in the email body.
Important: Page 999 is referenced by the supplied process, but its implementation is not part of the uploaded Page 7 export. The image-serving page must therefore be configured to return the selected product image correctly. It must also be accessible to the email recipient, or use an appropriate secure image-access mechanism.
11. Preparing Dynamic Email Placeholders Using APEX_JSON
The application uses the Oracle APEX_JSON package to generate a JSON object containing the dynamic product information.
The process retrieves product details from AUW_PRODUCTS and prepares the email placeholders.
PL/SQL Code β Preparing Email Data
DECLARE
l_prod_image_url VARCHAR2(4000);
l_placeholders CLOB;
BEGIN
FOR prod IN (
SELECT
CATEGORY,
PRODUCT_NAME,
PRODUCT_DESCRIPTION
FROM AUW_PRODUCTS
WHERE PRODUCT_ID = :P7_PRODUCT_ID
)
LOOP
apex_json.initialize_clob_output;
apex_json.open_object;
l_prod_image_url :=
apex_mail.get_instance_url
|| apex_page.get_url(
p_page => 999,
p_items => 'P999_PRODUCT_ID',
p_values => :P7_PRODUCT_ID
);
apex_json.write(
'APPLICATION_LINK',
apex_mail.get_instance_url
|| apex_page.get_url(p_page => 1)
);
apex_json.write(
'CATEGORY',
prod.CATEGORY
);
apex_json.write(
'PRODUCT_DESCRIPTION',
prod.PRODUCT_DESCRIPTION
);
apex_json.write(
'PRODUCT_NAME',
prod.PRODUCT_NAME
);
apex_json.write(
'PROD_IMAGE_URL',
l_prod_image_url
);
apex_json.close_object;
l_placeholders := apex_json.get_clob_output;
apex_json.free_output;
END LOOP;
END;
Understanding the Code
Step 1 β Retrieve Product Information
The SQL query retrieves the category, product name, and product description for the selected product.
Step 2 β Initialize JSON Output
APEX_JSON.INITIALIZE_CLOB_OUTPUT initializes a CLOB output buffer.
Step 3 β Open JSON Object
APEX_JSON.OPEN_OBJECT starts creating the JSON object.
Step 4 β Generate Product Image URL
The application generates the image URL using APEX_MAIL.GET_INSTANCE_URL and APEX_PAGE.GET_URL.
Step 5 β Write Dynamic Placeholders
The product information and image URL are added to the JSON object.
Step 6 β Retrieve Placeholder CLOB
APEX_JSON.GET_CLOB_OUTPUT returns the generated JSON content as a CLOB.
This CLOB is then passed to the email-sending process.
12. Sending Email Using APEX_MAIL
Oracle APEX provides the APEX_MAIL package for sending emails from APEX applications.
The implementation uses the APEX_MAIL.SEND procedure with three important parameters:
-
P_TO: Recipient email address. -
P_TEMPLATE_STATIC_ID: Email template Static ID. -
P_PLACEHOLDERS: Dynamic JSON placeholder content.
PL/SQL Code β Sending Email
apex_mail.send(
p_to => :P7_EMAIL_TO,
p_template_static_id => 'INCLUDING_IMAGES',
p_placeholders => l_placeholders
);
The email is sent using the selected template and the dynamic product information prepared earlier.
13. Pushing the Email Queue
After calling APEX_MAIL.SEND, the application executes:
apex_mail.push_queue;
This pushes queued email messages for delivery through the configured Oracle APEX mail infrastructure.
The complete process reports the success message:
Email has been sent out
This message indicates that the APEX page process completed successfully. Actual email delivery should still be verified through the mail queue and delivery logs.
14. Complete PL/SQL Process
The exported application uses a process named:
Send Email - Including Images
The following is the complete implementation from the supplied Page 7 export:
DECLARE
l_prod_image_url VARCHAR2(4000);
l_placeholders CLOB;
BEGIN
FOR prod IN (
SELECT
CATEGORY,
PRODUCT_NAME,
PRODUCT_DESCRIPTION
FROM AUW_PRODUCTS
WHERE PRODUCT_ID = :P7_PRODUCT_ID
)
LOOP
apex_json.initialize_clob_output;
apex_json.open_object;
l_prod_image_url :=
apex_mail.get_instance_url
|| apex_page.get_url(
p_page => 999,
p_items => 'P999_PRODUCT_ID',
p_values => :P7_PRODUCT_ID
);
apex_json.write(
'APPLICATION_LINK',
apex_mail.get_instance_url
|| apex_page.get_url(p_page => 1)
);
apex_json.write(
'CATEGORY',
prod.CATEGORY
);
apex_json.write(
'PRODUCT_DESCRIPTION',
prod.PRODUCT_DESCRIPTION
);
apex_json.write(
'PRODUCT_NAME',
prod.PRODUCT_NAME
);
apex_json.write(
'PROD_IMAGE_URL',
l_prod_image_url
);
apex_json.close_object;
l_placeholders := apex_json.get_clob_output;
apex_json.free_output;
apex_mail.send(
p_to => :P7_EMAIL_TO,
p_template_static_id => 'INCLUDING_IMAGES',
p_placeholders => l_placeholders
);
END LOOP;
apex_mail.push_queue;
END;
15. Complete Application Workflow
The following flowchart illustrates how the application works from product selection to email delivery.
flowchart TD
A([Open Oracle APEX Page]) --> B[Select Product]
B --> C[Refresh Product Details Report]
C --> D[Display Product Information and Image]
D --> E[Enter Recipient Email]
E --> F[Click Send Email]
F --> G[Execute PL/SQL Process]
G --> H[Retrieve Product Details]
H --> I[Generate Product Image URL]
I --> J[Prepare JSON Placeholders]
J --> K[Call APEX_MAIL.SEND]
K --> L[Push Email Queue]
L --> M([Email Queued for Delivery])
16. Important Technical Considerations
Before implementing this solution in a production environment, consider the following:
1. Image Accessibility
The product image URL must be accessible to the recipientβs email client. A URL that works only inside an authenticated APEX session may not display in external email clients.
2. Email Template Configuration
Ensure that the INCLUDING_IMAGES template exists and its placeholder names match those used in the PL/SQL process.
3. Email Server Configuration
Configure the Oracle APEX instanceβs email settings and SMTP infrastructure before sending emails.
4. Email Queue Monitoring
Check the APEX mail queue and mail logs to confirm that messages are processed and delivered.
5. Recipient Validation
Validate the recipient email address before executing the sending process.
6. Image Handling
Use an appropriate image size and format to ensure that product images load efficiently in email clients.
7. Error Handling
Add exception handling and appropriate logging so that failed email operations can be diagnosed.
17. Real-World Business Use Cases
This approach can be extended to several business scenarios:
-
Product catalog email notifications.
-
Customer product recommendations.
-
Promotional product emails.
-
Product quotation sharing.
-
E-commerce product notifications.
-
Inventory update notifications.
-
Product approval communications.
-
Sales and marketing communication.
The same approach can be adapted to send dynamic information from other Oracle APEX business modules.
18. Key Technical Highlights
This project demonstrates practical integration of the following Oracle technologies:
| Technology | Implementation |
|---|---|
| Oracle APEX | Email application interface |
| SQL | Product data retrieval |
| PL/SQL | Email preparation and execution |
| APEX_JSON | Dynamic placeholder generation |
| APEX_MAIL | Email sending |
| APEX_PAGE | Dynamic URL generation |
| Dynamic Actions | Automatic report refresh |
| Email Templates | Reusable email layout |
| BLOB | Product image storage |
19. Conclusion
Sending product information through email templates is a useful feature for business applications. Oracle APEX makes this process straightforward by combining reusable email templates, dynamic placeholders, SQL, PL/SQL, and the APEX_MAIL package.
In this project, I demonstrated how users can select a product, preview its details and image, enter an email address, and send dynamic product information using an Oracle APEX email template.
This implementation highlights the flexibility of Oracle APEX for building database-driven email solutions and integrating product information with business communication workflows.
I hope this article helps Oracle APEX developers understand how to work with email templates, dynamic placeholders, product image URLs, and the APEX_MAIL package.
Oracle ACE Associate Contribution
This article is part of my ongoing technical knowledge-sharing contributions to the Oracle community as I work toward the Oracle ACE Associate program.
Through this implementation, I aim to demonstrate practical Oracle APEX email integration techniques and help fellow developers understand how to create dynamic email solutions using Oracle APEX Email Templates, APEX_JSON, and APEX_MAIL.
Article Title: Sending Email Templates Including Product Images in Oracle APEX
Category: Oracle APEX Development / Email Integration
Technologies: Oracle APEX, SQL, PL/SQL, APEX_MAIL, APEX_JSON, Email Templates
Oracle Solutions We believe in delivering tangible results for our customers in a cost-effective manner