Developer Tools
Application Express
| How-To Document
Send E-Mail from Application Express (formerly called HTML DB) Applications
Date: 16-Dec-2003 After completing this How-To, you should be able to:
Table of Contents
Sending e-mail within an Oracle HTML DB application is accomplished by using the supplied PL/SQL package HTMLDB_MAIL. To send mail you create a PL/SQL process on a page that calls the HTMLDB_MAIL package. This document describes how to create a process in an application to send e-mail. It also describes how to extend the demonstration application, Sample Application, to add simple workflow by sending an e-mail confirmation to the orderer and a notification e-mail to the order fulfiller. E-mail is not sent immediately from Oracle HTML DB but rather is stored in a temporary queue until a DBMS_JOB pushes the queue. The DBMS_JOB utilizes two preferences named SMTP_HOST_ADDRESS and SMTP_HOST_PORT to send mail in the queue. By default, these preferences are set to localhost and 25. If the server where Oracle HTML DB is installed is not configured for SMTP services, you will need to change the SMTP_HOST_ADDRESS preference. Check with your Oracle HTML DB administrator to make sure the instance you are using is properly configured to send e-mail. Software Requirements
First you need to add yourself as a customer in the demonstration application, Sample Application. Be sure you include your valid e-mail address so you will know whether the procedure you create later works properly. To add yourself as a customer in Sample Application:
The next step is to add a process to the Confirm Order page of the Enter New Order Wizard that sends a confirmation e-mail to the customer. You do this by creating a new PL/SQL process on page 206 of Sample Application to call the SEND procedure of the HTMLDB_MAIL package to send a confirmation e-mail to the customer when the Confirm Order button is clicked. The following is a description of the SEND procedure of the HTMLDB_MAIL package. PROCEDURE SEND Argument Name Type In/Out Default? ------------------------------ ----------------------- ------ -------- P_TO VARCHAR2 IN P_FROM VARCHAR2 IN P_BODY VARCHAR2 IN P_BODY_HTML VARCHAR2 IN DEFAULT P_SUBJ VARCHAR2 IN DEFAULT P_CC VARCHAR2 IN DEFAULT P_BCC VARCHAR2 IN DEFAULT To create a PL/SQL procedure to send a confirmation e-mail:
Figure 1: Process to Send Confirmation Create the Notification E-mail ProcessThe next step is to send an e-mail notification to the order fulfiller indicating that a new order is ready to be processed. This e-mail should include a link so the user can view the new order. Since the e-mail includes a link, the body of the email will also be passed using the parameter P_BODY_HTML. To test the process, replace the e-mail addresses in the process below with your e-mail address. To create a PL/SQL procedure to send a notification e-mail to the order fulfiller:
Run the Sample Application and enter a new order. You should now receive both the confirmation and the notification e-mails. Feel free to discuss this how-to in the OTN HTML DB Discussion Forum. |